MCPcopy Index your code
hub / github.com/conventionalcommit/commitlint / newConfigCmd

Function newConfigCmd

internal/cmd/cmd.go:110–175  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

108}
109
110func newConfigCmd() *cli.Command {
111 createCmd := &cli.Command{
112 Name: "create",
113 Usage: "Create a default config file",
114 Flags: []cli.Flag{
115 &cli.BoolFlag{
116 Name: "replace",
117 Aliases: []string{"r"},
118 Usage: "Overwrite if the file already exists",
119 },
120 &cli.StringFlag{
121 Name: "file",
122 Usage: "Output file name",
123 Value: ".commitlint.yaml",
124 },
125 &cli.BoolFlag{
126 Name: "all",
127 Usage: "Write all settings (not just enabled rules)",
128 },
129 },
130 Action: func(ctx *cli.Context) error {
131 isReplace := ctx.Bool("replace")
132 fileName := ctx.String("file")
133 all := ctx.Bool("all")
134 err := configCreate(fileName, isReplace, all)
135 if err != nil {
136 if isConfExists(err) {
137 fmt.Println("config file already exists")
138 fmt.Println("use --replace to overwrite it")
139 return nil
140 }
141 return err
142 }
143 fmt.Println("config file created")
144 return nil
145 },
146 }
147
148 checkCmd := &cli.Command{
149 Name: "check",
150 Usage: "Check if a config file is valid",
151 ArgsUsage: "<config-file>",
152 Action: func(ctx *cli.Context) error {
153 confFile := ctx.Args().First()
154 if confFile == "" {
155 return fmt.Errorf("please provide a config file path\n\nUsage: commitlint config check <config-file>")
156 }
157 errs := configCheck(confFile)
158 if len(errs) == 0 {
159 fmt.Printf("%s: valid\n", confFile)
160 return nil
161 }
162 if len(errs) == 1 {
163 return errs[0]
164 }
165 merr := multiError(errs)
166 return &merr
167 },

Callers 1

newCliAppFunction · 0.85

Calls 5

configCreateFunction · 0.85
isConfExistsFunction · 0.85
configCheckFunction · 0.85
multiErrorTypeAlias · 0.85
StringMethod · 0.45

Tested by

no test coverage detected