Skip to content

Commit

Permalink
feat(cmd): add file flag to config/create command
Browse files Browse the repository at this point in the history
  • Loading branch information
muthukrishnan24 committed Jan 29, 2022
1 parent f1c060b commit a81a020
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/cmd/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func hookCreate(confPath string, isReplace bool) error {
}

// configCreate is the callback function for create config command
func configCreate(isReplace bool) error {
func configCreate(fileName string, isReplace bool) error {
defConf := config.Default()
outPath := filepath.Join(".", config.ConfigFile)
outPath := filepath.Join(".", fileName)
// if config file already exists skip creating or overwriting it
if _, err := os.Stat(outPath); !os.IsNotExist(err) {
if !isReplace {
Expand Down
8 changes: 7 additions & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@ func configCmd() *cli.Command {
Usage: "Replace conf file if already exists",
Value: false,
},
&cli.StringFlag{
Name: "file",
Usage: "Config file name",
Value: ".commitlint.yaml",
},
},
Action: func(ctx *cli.Context) error {
isReplace := ctx.Bool("replace")
err := configCreate(isReplace)
fileName := ctx.String("file")
err := configCreate(fileName, isReplace)
if err != nil {
if isConfExists(err) {
fmt.Println("config create failed")
Expand Down

0 comments on commit a81a020

Please sign in to comment.