Skip to content

Commit

Permalink
Remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
aswinkarthik committed Oct 8, 2019
1 parent dd5971a commit b0ee231
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ Most suitable for csv files created from database tables`,
PreRunE: func(cmd *cobra.Command, args []string) error {
// Validate args
if len(args) != 2 {
return fmt.Errorf("Pass 2 files. Usage: csvdiff <base-csv> <delta-csv>")
}

if err := isValidFile(args[0]); err != nil {
return err
}

if err := isValidFile(args[1]); err != nil {
return err
return fmt.Errorf("pass 2 files. Usage: csvdiff <base-csv> <delta-csv>")
}

return nil
Expand Down Expand Up @@ -110,23 +102,6 @@ func runContext(
return NewFormatter(outputStream, errorStream, ctx).Format(diff)
}

func isValidFile(path string) error {
fileInfo, err := os.Stat(path)

if os.IsNotExist(err) {
return fmt.Errorf("%s does not exist", path)
}

if fileInfo.IsDir() {
return fmt.Errorf("%s is a directory. Please pass a file", path)
}

if err != nil {
return fmt.Errorf("error reading path: %v", err)
}

return nil
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
Expand Down Expand Up @@ -157,15 +132,6 @@ func init() {
rootCmd.Flags().BoolVarP(&timed, "time", "", false, "Measure time")
}

func newReadCloser(filename string) (io.ReadCloser, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}

return file, nil
}

func timeTrack(start time.Time, name string) {
elapsed := time.Since(start)
_, _ = fmt.Fprintln(os.Stderr, fmt.Sprintf("%s took %s", name, elapsed))
Expand Down

0 comments on commit b0ee231

Please sign in to comment.