Add init command (#33)
Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/gitea/changelog/pulls/33 Reviewed-by: 6543 <6543@noreply.gitea.io> Reviewed-by: Guillermo Prandi <guillep2k@noreply.gitea.io>
This commit is contained in:
parent
601bf3f04c
commit
3c1b200883
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## [0.1.0](https://gitea.com/gitea/changelog/pulls?q=&type=all&state=closed&milestone=1231) - 2020-01-25
|
## [0.1.0](https://gitea.com/gitea/changelog/pulls?q=&type=all&state=closed&milestone=1231) - 2020-01-25
|
||||||
* FEATURES
|
* FEATURES
|
||||||
|
* Add init command (#33)
|
||||||
* Add subcommand to display contributors of milestone (#10)
|
* Add subcommand to display contributors of milestone (#10)
|
||||||
* BUGFIXES
|
* BUGFIXES
|
||||||
* Fix README about import path (#22)
|
* Fix README about import path (#22)
|
||||||
|
@ -22,7 +22,7 @@ const (
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
defaultConfig = []byte(` + "`" + `%s` + "`" + `)
|
DefaultConfig = []byte(` + "`" + `%s` + "`" + `)
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
|
46
cmd/init.go
Normal file
46
cmd/init.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"code.gitea.io/changelog/config"
|
||||||
|
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Init = &cli.Command{
|
||||||
|
Name: "init",
|
||||||
|
Usage: "Initialize a default .changelog.yml",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "name",
|
||||||
|
Aliases: []string{"n"},
|
||||||
|
Usage: "Name of the changelog config",
|
||||||
|
Value: ".changelog.yml",
|
||||||
|
Destination: &nameFlag,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: runInit,
|
||||||
|
}
|
||||||
|
nameFlag string
|
||||||
|
)
|
||||||
|
|
||||||
|
func runInit(cmd *cli.Context) error {
|
||||||
|
if _, err := os.Stat(nameFlag); err == nil {
|
||||||
|
return fmt.Errorf("file '%s' already exists", nameFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(nameFlag, config.DefaultConfig, os.ModePerm); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Config initialized at '%s'\n", nameFlag)
|
||||||
|
return nil
|
||||||
|
}
|
@ -11,7 +11,7 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultConfig []byte
|
var DefaultConfig []byte
|
||||||
|
|
||||||
// Group is a grouping of PRs
|
// Group is a grouping of PRs
|
||||||
type Group struct {
|
type Group struct {
|
||||||
@ -35,7 +35,7 @@ func New(configPath string) (*Config, error) {
|
|||||||
var err error
|
var err error
|
||||||
var configContent []byte
|
var configContent []byte
|
||||||
if len(configPath) == 0 {
|
if len(configPath) == 0 {
|
||||||
configContent = defaultConfig
|
configContent = DefaultConfig
|
||||||
} else {
|
} else {
|
||||||
configContent, err = ioutil.ReadFile(configPath)
|
configContent, err = ioutil.ReadFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
defaultConfig = []byte(`# The full repository name
|
DefaultConfig = []byte(`# The full repository name
|
||||||
repo: go-gitea/gitea
|
repo: go-gitea/gitea
|
||||||
|
|
||||||
# Service type (gitea or github)
|
# Service type (gitea or github)
|
||||||
|
3
main.go
3
main.go
@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"code.gitea.io/changelog/cmd"
|
"code.gitea.io/changelog/cmd"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +31,6 @@ func main() {
|
|||||||
Name: "milestone",
|
Name: "milestone",
|
||||||
Aliases: []string{"m"},
|
Aliases: []string{"m"},
|
||||||
Usage: "Targeted milestone",
|
Usage: "Targeted milestone",
|
||||||
Required: true,
|
|
||||||
Destination: &cmd.MilestoneFlag,
|
Destination: &cmd.MilestoneFlag,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
@ -61,6 +61,7 @@ func main() {
|
|||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
cmd.Generate,
|
cmd.Generate,
|
||||||
cmd.Contributors,
|
cmd.Contributors,
|
||||||
|
cmd.Init,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user