Skip to content

Commit

Permalink
Add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
keyneston committed Apr 29, 2021
1 parent 63c5fc1 commit 58f9cbe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ jobs:
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_BREW_TOKEN: ${{ secrets.GH_BREW_TOKEN }}
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ brews:
name: homebrew-tap
token: "{{ .Env.GH_BREW_TOKEN }}"


# Your app's homepage.
# Default is empty.
homepage: "https://github.com/keyneston/mktable"
Expand Down
25 changes: 22 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/keyneston/mktable/table"
)

var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)

type Config struct {
SkipHeaders bool
Seperator string
Format FormatValue
MaxPadding int
Reformat bool
Format FormatValue
Seperator string
SkipHeaders bool
Version bool

Alignments ParseAlignments

Expand All @@ -35,6 +44,7 @@ func (c *Config) Register(f *flag.FlagSet) *Config {
c.fset.Var(&c.Format, "f", fmt.Sprintf("Set the format. Available formats: %v", allFormats))
c.fset.Var(&c.Format, "format", "Alias for -f")
c.fset.Var(&c.Alignments, "a", "Set column alignments; Can be called multiple times and/or comma separated. Arrow indicates direction '<' left, '>' right, '=' center; Columns are zero indexed; e.g. -a '0<,1>,2='")
c.fset.BoolVar(&c.Version, "v", false, "Print version info")

return c
}
Expand All @@ -54,6 +64,11 @@ func main() {
log.Fatalf("Error: %v", err)
}

if c.Version {
PrintVersion(os.Args[0])
os.Exit(0)
}

tableConfig := table.TableConfig{
MaxPadding: c.MaxPadding,
SkipHeaders: c.SkipHeaders,
Expand All @@ -69,3 +84,7 @@ func main() {
tb.Read(os.Stdin)
tb.Write(os.Stdout)
}

func PrintVersion(bin string) {
fmt.Printf("%s\nversion: %s\ncommit: %v\nbuilt-on: %v\nbuilt-by: %v\n", filepath.Base(bin), version, commit, date, builtBy)
}

0 comments on commit 58f9cbe

Please sign in to comment.