Skip to content

Commit 889288d

Browse files
feat: add command to verify config file
1 parent 3e11a11 commit 889288d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

cmd/callback.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,25 @@ func configCreateCallback(ctx *cli.Context) error {
7676
}
7777
return nil
7878
}
79+
80+
func verifyCallback(ctx *cli.Context) error {
81+
confFlag := ctx.String("config")
82+
83+
confPath, useDefault, err := config.GetConfigPath(confFlag)
84+
if err != nil {
85+
return cli.Exit(err, ErrExitCode)
86+
}
87+
88+
if useDefault {
89+
fmt.Println("no config file found, default config will be used")
90+
return nil
91+
}
92+
93+
_, _, err = getLinter(confPath)
94+
if err != nil {
95+
return cli.Exit(err, ErrExitCode)
96+
}
97+
98+
fmt.Printf("%s config is valid\n", confPath)
99+
return nil
100+
}

cmd/cmd.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ func New(versionNo, commitHash, builtTime string) *cli.App {
7979
},
8080
}
8181

82+
verifyCmd := &cli.Command{
83+
Name: "verify",
84+
Usage: "verifies commitlint config",
85+
Flags: []cli.Flag{
86+
&cli.StringFlag{
87+
Name: "config",
88+
Aliases: []string{"c", "conf"},
89+
Value: "",
90+
Usage: "optional config file `conf.yaml`",
91+
},
92+
},
93+
Action: verifyCallback,
94+
}
95+
8296
return &cli.App{
8397
Name: "commitlint",
8498
Usage: "linter for conventional commits",
@@ -87,6 +101,7 @@ func New(versionNo, commitHash, builtTime string) *cli.App {
87101
createCmd,
88102
initCmd,
89103
lintCmd,
104+
verifyCmd,
90105
versionCmd,
91106
},
92107
}

0 commit comments

Comments
 (0)