2021-04-11 09:11:41 +00:00
package cli
2021-04-23 03:51:27 +00:00
import (
"os"
"github.com/urfave/cli/v2"
2022-11-27 18:28:59 +00:00
"github.com/make-go-great/color-go"
2021-04-23 03:51:27 +00:00
)
2021-04-11 09:11:41 +00:00
const (
2022-02-07 13:59:20 +00:00
name = "changeloguru"
usage = "generate changelog from conventional commits"
2021-04-11 09:11:41 +00:00
2022-08-15 17:47:25 +00:00
commandGenerateName = "generate"
commandGenerateUsage = "generate changelog"
flagVerboseName = "verbose"
flagVerboseUsage = "show what is going on"
flagVersionName = "version"
flagVersionUsage = "`VERSION` to generate, follow Semantic Versioning"
flagFromName = "from"
2023-07-16 14:03:39 +00:00
flagFromUsage = "`FROM COMMIT`, which is kinda new commit, default is latest commit"
2022-08-15 17:47:25 +00:00
flagToName = "to"
2023-07-16 14:03:39 +00:00
flagToUsage = "`TO COMMIT`, which is kinda old commit, default is oldest commit"
2022-08-15 17:47:25 +00:00
flagScopeName = "scope"
flagScopeUsage = "scope to generate"
flagRepositoryName = "repository"
flagRepositoryUsage = "`REPOSITORY` directory path"
flagOutputName = "output"
flagOutputUsage = "`OUTPUT` directory path, relative to `REPOSITORY` path"
flagFilenameName = "filename"
flagFilenameUsage = "output `FILENAME`"
flagFiletypeName = "filetype"
flagFiletypeUsage = "output `FILETYPE`"
flagDryRunName = "dry-run"
flagDryRunUsage = "demo run without actually changing anything"
flagInteractiveName = "interactive"
flagInteractiveUsage = "interactive mode"
2023-06-29 10:52:46 +00:00
flagInteractiveFromName = "interactive-from"
2023-07-16 14:03:39 +00:00
flagInteractiveFromUsage = "enable ask `FROM COMMIT` in interactive mode"
flagInteractiveToName = "interactive-to"
flagInteractiveToUsage = "enable ask `TO COMMIT` in interactive mode, otherwise use latest SemVer tag"
2023-06-29 10:52:46 +00:00
2022-09-04 15:44:57 +00:00
flagAutoGitCommitName = "auto-commit"
flagAutoGitCommitUsage = "enable auto git commit after generating changelog"
flagAutoGitTagName = "auto-tag"
flagAutoGitTagUsage = "enable auto git tag after generating changelog, only works if auto-commit is enabled"
flagAutoGitPushName = "auto-push"
flagAutoGitPushUsage = "enable auto git push after generating changelog, only works if auto-commit is enabled, if auto-tag is enabled will auto git push tag too"
2021-04-11 09:11:41 +00:00
)
var (
2022-08-15 17:47:25 +00:00
commandGenerateAliases = [ ] string { "g" , "gen" }
flagVerboseAliases = [ ] string { "v" }
flagInteractiveAliases = [ ] string { "i" }
2021-04-11 09:11:41 +00:00
)
2021-04-23 03:51:27 +00:00
type App struct {
cliApp * cli . App
}
func NewApp ( ) * App {
2021-04-11 09:11:41 +00:00
a := & action { }
2021-04-23 03:51:27 +00:00
cliApp := & cli . App {
2022-02-07 13:59:20 +00:00
Name : name ,
Usage : usage ,
2021-04-11 09:11:41 +00:00
Commands : [ ] * cli . Command {
{
2022-08-15 17:47:25 +00:00
Name : commandGenerateName ,
Aliases : commandGenerateAliases ,
Usage : commandGenerateUsage ,
2021-04-11 09:11:41 +00:00
Flags : [ ] cli . Flag {
2021-04-23 03:51:27 +00:00
& cli . BoolFlag {
2022-08-15 17:47:25 +00:00
Name : flagVerboseName ,
Aliases : flagVerboseAliases ,
Usage : flagVerboseUsage ,
2021-04-23 03:51:27 +00:00
} ,
2022-02-07 15:52:35 +00:00
& cli . StringFlag {
2022-08-15 17:47:25 +00:00
Name : flagVersionName ,
Usage : flagVersionUsage ,
2022-02-07 15:52:35 +00:00
} ,
2021-04-11 09:11:41 +00:00
& cli . StringFlag {
2022-08-15 17:47:25 +00:00
Name : flagFromName ,
Usage : flagFromUsage ,
2021-04-11 09:11:41 +00:00
} ,
& cli . StringFlag {
2022-08-15 17:47:25 +00:00
Name : flagToName ,
Usage : flagToUsage ,
2021-04-11 09:11:41 +00:00
} ,
& cli . StringSliceFlag {
2022-08-15 17:47:25 +00:00
Name : flagScopeName ,
Usage : flagScopeUsage ,
2021-04-11 09:11:41 +00:00
} ,
& cli . StringFlag {
2022-08-15 17:47:25 +00:00
Name : flagRepositoryName ,
Usage : flagRepositoryUsage ,
2021-04-11 09:11:41 +00:00
} ,
& cli . StringFlag {
2022-08-15 17:47:25 +00:00
Name : flagOutputName ,
Usage : flagOutputUsage ,
2021-04-11 09:11:41 +00:00
} ,
& cli . StringFlag {
2022-08-15 17:47:25 +00:00
Name : flagFilenameName ,
Usage : flagFilenameUsage ,
2021-04-11 09:11:41 +00:00
} ,
& cli . StringFlag {
2022-08-15 17:47:25 +00:00
Name : flagFiletypeName ,
Usage : flagFiletypeUsage ,
2021-04-11 09:11:41 +00:00
} ,
2021-04-14 07:31:00 +00:00
& cli . BoolFlag {
2022-08-15 17:47:25 +00:00
Name : flagDryRunName ,
Usage : flagDryRunUsage ,
2021-04-14 07:31:00 +00:00
} ,
2022-02-07 14:22:20 +00:00
& cli . BoolFlag {
2022-08-15 17:47:25 +00:00
Name : flagInteractiveName ,
Usage : flagInteractiveUsage ,
Aliases : flagInteractiveAliases ,
2022-02-07 14:22:20 +00:00
} ,
2023-06-29 10:52:46 +00:00
& cli . BoolFlag {
Name : flagInteractiveFromName ,
Usage : flagInteractiveFromUsage ,
} ,
2023-07-16 14:03:39 +00:00
& cli . BoolFlag {
Name : flagInteractiveToName ,
Usage : flagInteractiveToUsage ,
} ,
2022-07-03 16:19:14 +00:00
& cli . BoolFlag {
2022-09-04 15:44:57 +00:00
Name : flagAutoGitCommitName ,
Usage : flagAutoGitCommitUsage ,
2022-07-03 16:19:14 +00:00
} ,
2022-09-04 16:30:16 +00:00
& cli . BoolFlag {
Name : flagAutoGitTagName ,
Usage : flagAutoGitTagUsage ,
} ,
& cli . BoolFlag {
Name : flagAutoGitPushName ,
Usage : flagAutoGitPushUsage ,
} ,
2021-04-11 09:11:41 +00:00
} ,
Action : a . RunGenerate ,
} ,
} ,
Action : a . RunHelp ,
}
2021-04-23 03:51:27 +00:00
return & App {
cliApp : cliApp ,
}
}
func ( a * App ) Run ( ) {
if err := a . cliApp . Run ( os . Args ) ; err != nil {
2022-02-07 13:59:20 +00:00
color . PrintAppError ( name , err . Error ( ) )
2021-04-23 03:51:27 +00:00
}
2021-04-11 09:11:41 +00:00
}