Skip to content

Commit

Permalink
Change input-file option name to delta-file
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinkarthik committed Apr 15, 2018
1 parent 8a9b106 commit 98122bd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 39 deletions.
8 changes: 4 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Config struct {
KeyPositions []int
Encoder string
Base string
Input string
Delta string
Additions string
Modifications string
}
Expand All @@ -42,12 +42,12 @@ func (c Config) GetEncoder() encoder.Encoder {
}
}

func (c Config) GetBase() io.Reader {
func (c Config) GetBaseReader() io.Reader {
return getReader(c.Base)
}

func (c Config) GetInput() io.Reader {
return getReader(c.Input)
func (c Config) GetDeltaReader() io.Reader {
return getReader(c.Delta)
}

func (c Config) AdditionsWriter() io.WriteCloser {
Expand Down
16 changes: 0 additions & 16 deletions cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,3 @@ func TestGetKeyPositions(t *testing.T) {
config = Config{KeyPositions: []int{}}
assert.Equal(t, []int{0}, config.GetKeyPositions())
}

// func TestReader(t *testing.T) {
// config := Config{Base: "STDIN"}
// assert.Equal(t, os.Stdin, config.GetReader())
//
// config = Config{Base: "-"}
// assert.Equal(t, os.Stdin, config.GetReader())
// }

// func TestWriter(t *testing.T) {
// config := Config{Base: "STDOUT"}
// assert.Equal(t, os.Stdout, config.GetWriter())
//
// config = Config{Base: "-"}
// assert.Equal(t, os.Stdout, config.GetWriter())
// }
8 changes: 3 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "csv-digest",
Short: "Takes in a csv and creates a digest of each line",
Long: `Takes a Csv file and creates a digest for each line.
The tool can output to stdout or a file in plaintext.
It can also serialize the output as a binary file for any other go program to consume directly`,
Use: "csv-diff",
Short: "A CSV diff tool",
Long: "Differentiates two csv files and finds out the additions and modifications",
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) {
Expand Down
25 changes: 11 additions & 14 deletions cmd/digest.go → cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ import (

// digestCmd represents the digest command
var digestCmd = &cobra.Command{
Use: "digest <csv-file>",
Short: "Takes in a csv and creates a digest of each line",
Long: `Takes a Csv file and creates a digest for each line.
The tool can output to stdout or a file in plaintext.
It can also serialize the output as a binary file for any other go program to consume directly`,
Use: "run",
Short: "run diff between base-csv and delta-csv",
Run: func(cmd *cobra.Command, args []string) {
runDigest()
run()
},
}

Expand All @@ -56,19 +53,19 @@ func init() {
// is called directly, e.g.:
// digestCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

digestCmd.Flags().StringVarP(&config.Base, "base", "b", "", "Input csv to be used as base")
digestCmd.Flags().StringVarP(&config.Input, "input", "i", "", "The new csv file on which diff should be done")
digestCmd.Flags().StringVarP(&config.Base, "base", "b", "", "The base csv file")
digestCmd.Flags().StringVarP(&config.Delta, "delta", "d", "", "The delta csv file")
digestCmd.Flags().StringVarP(&config.Encoder, "encoder", "e", "json", "Encoder to use to output the digest. Available Encoders: "+strings.Join(GetEncoders(), ","))
digestCmd.Flags().IntSliceVarP(&config.KeyPositions, "key-positions", "k", []int{0}, "Primary key positions of the Input CSV as comma separated values Eg: 1,2")
digestCmd.Flags().BoolVarP(&debug, "debug", "", false, "Debug mode")
digestCmd.Flags().StringVarP(&config.Additions, "additions", "a", "STDOUT", "Output stream for the additions in delta file")
digestCmd.Flags().StringVarP(&config.Modifications, "modifications", "m", "STDOUT", "Output stream for the modifications in delta file")

digestCmd.MarkFlagRequired("base")
digestCmd.MarkFlagRequired("input")
digestCmd.MarkFlagRequired("delta")
}

func runDigest() {
func run() {
if str, err := json.Marshal(config); err == nil && debug {
fmt.Println(string(str))
} else if err != nil {
Expand All @@ -78,14 +75,14 @@ func runDigest() {
baseConfig := digest.DigestConfig{
KeyPositions: config.GetKeyPositions(),
Encoder: config.GetEncoder(),
Reader: config.GetBase(),
Reader: config.GetBaseReader(),
Writer: os.Stdout,
}

inputConfig := digest.DigestConfig{
deltaConfig := digest.DigestConfig{
KeyPositions: config.GetKeyPositions(),
Encoder: config.GetEncoder(),
Reader: config.GetInput(),
Reader: config.GetDeltaReader(),
Writer: os.Stdout,
SourceMap: true,
}
Expand All @@ -98,7 +95,7 @@ func runDigest() {
go generateInBackground("base", baseConfig, &wg, baseChannel)

wg.Add(1)
go generateInBackground("delta", inputConfig, &wg, deltaChannel)
go generateInBackground("delta", deltaConfig, &wg, deltaChannel)

wg.Add(1)
go compareInBackgroud(baseChannel, deltaChannel, &wg)
Expand Down

0 comments on commit 98122bd

Please sign in to comment.