Skip to content

Commit

Permalink
Add version option
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinkarthik committed Apr 29, 2018
1 parent 143c0b4 commit 80fabed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ import (
"github.com/spf13/viper"
)

var cfgFile string
var timed bool
var (
cfgFile string
timed bool
version bool
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand All @@ -43,6 +46,10 @@ var rootCmd = &cobra.Command{
Long: `Differentiates two csv files and finds out the additions and modifications.
Most suitable for csv files created from database tables`,
PreRunE: func(cmd *cobra.Command, args []string) error {
if version {
return nil
}

if len(args) != 2 {
return errors.New("Pass 2 files. Usage: csvdiff <base-csv> <delta-csv>")
}
Expand All @@ -51,6 +58,11 @@ Most suitable for csv files created from database tables`,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
if version {
fmt.Println(VersionString)
return
}

if timed {
defer timeTrack(time.Now(), "csvdiff")
}
Expand Down Expand Up @@ -104,6 +116,7 @@ func init() {
rootCmd.Flags().IntSliceVarP(&config.ValueColumnPositions, "columns", "", []int{}, "Selectively compare positions in CSV Eg: 1,2. Default is entire row")

rootCmd.Flags().BoolVarP(&timed, "time", "", false, "Measure time")
rootCmd.Flags().BoolVarP(&version, "version", "", false, "Display version")
}

// initConfig reads in config file and ENV variables if set.
Expand Down
4 changes: 4 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package cmd

// VersionString to display on --version call
const VersionString = "csvdiff v0.1.1"

0 comments on commit 80fabed

Please sign in to comment.