diff --git a/.gitignore b/.gitignore index 9843089..f3470a4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .idea .DS_Store .vscode -TODO.md \ No newline at end of file +TODO.md +veronica.yaml \ No newline at end of file diff --git a/cmd/report.go b/cmd/report.go index 6520953..c7e89a4 100644 --- a/cmd/report.go +++ b/cmd/report.go @@ -12,21 +12,23 @@ import ( var reportCmd = &cobra.Command{ Use: "report", - Example: ` veronica report .`, + Example: ` veronica report --old HEAD~1 --new HEAD`, Short: "report the scope of impact of code changes", - Run: func(command *cobra.Command, args []string) { - if len(args) != 1 { - log.Fatal("Usage: veronica report ") + if oldCommit == "" { + log.Fatal("Usage: veronica report --old --new ") + } + if newCommit == "" { + log.Fatal("Usage: veronica report --old --new ") } - cmd := exec.Command("git", "diff", "--name-only", "HEAD~1", "HEAD") + cmd := exec.Command("git", "diff", "--name-only", oldCommit, newCommit) output, err := cmd.CombinedOutput() if err != nil { log.Fatalf("git diff: %s", output) } - project, err := parser.NewProject(args[0]) + project, err := parser.NewProject(repo) if err != nil { log.Fatalf("load project: %s", err) } @@ -53,6 +55,9 @@ var reportCmd = &cobra.Command{ var ( outputFormat string + oldCommit string + newCommit string + repo string ) const ( @@ -62,4 +67,7 @@ const ( func init() { reportCmd.Flags().StringVarP(&outputFormat, "format", "f", OutputFormatOneLine, "output format, options: oneline, text") + reportCmd.Flags().StringVarP(&oldCommit, "old", "o", "", "old commit") + reportCmd.Flags().StringVarP(&newCommit, "new", "n", "", "new commit") + reportCmd.Flags().StringVarP(&repo, "repo", "r", ".", "repo path") }