Skip to content

Commit d5ac36d

Browse files
committed
feat: finish migration to the cmd structure
added the commitlog cmd/subpackage
1 parent 23d0575 commit d5ac36d

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
CHANGELOG.md
2-
commitlog
2+
./commitlog

cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ func Init() {
2525
}
2626

2727
// Default Command, parse all flags
28-
commitlogCmd.Run()
28+
commitlogCmd.Run(os.Args)
2929
}

cmd/commitlog/commitlog.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package commitlog
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
8+
clog "github.com/barelyhuman/commitlog/log"
9+
)
10+
11+
var clogCmd *flag.FlagSet
12+
var repoPath *string
13+
var startCommit *string
14+
var endCommit *string
15+
var inclusionFlags *string
16+
var skipClassification *bool
17+
18+
// Install - add flags and other options
19+
func Install() {
20+
clogCmd = flag.NewFlagSet("release", flag.ExitOnError)
21+
repoPath = clogCmd.String("p", ".", "path to the repository, points to the current working directory by default")
22+
startCommit = clogCmd.String("s", "", "commit hash string / revision (ex. HEAD, HEAD^, HEAD~2) \n to start collecting commit messages from")
23+
endCommit = clogCmd.String("e", "", "commit hash string / revision (ex. HEAD, HEAD^, HEAD~2) \n to stop collecting commit message at")
24+
inclusionFlags = clogCmd.String("i", clog.SupportedKeys, "commit types to be includes")
25+
skipClassification = clogCmd.Bool("skip", false, "if true will skip trying to classify and just give a list of changes")
26+
}
27+
28+
// Run - execute the command
29+
func Run(args []string) {
30+
clogCmd.Parse(args)
31+
changelog, err := clog.CommitLog(*repoPath, *startCommit, *endCommit, *inclusionFlags, *skipClassification)
32+
33+
if err.Err != nil {
34+
log.Fatal(err.Message, err.Err)
35+
}
36+
37+
fmt.Println(changelog)
38+
}

0 commit comments

Comments
 (0)