github.com/kamontat/dot-github@v1.2.0/cli.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "io" 7 "os" 8 ) 9 10 type Parsed struct { 11 Help bool 12 Version bool 13 IssueOnly bool 14 PROnly bool 15 ContributingOnly bool 16 flags *flag.FlagSet 17 } 18 19 const Usage = `Usage: dot-github [flags] 20 21 A CLI tool to generate GitHub files such as CONTRIBUTING.md, 22 ISSUE_TEMPLATE.md and PULL_REQUEST_TEMPLATE.md from template files in 23 '~/.github' directory. 24 25 You can control which template should be used and it attempts to generate 26 all by default. 27 28 Below templates are looked by dot-github command. 29 ($DOT_GITHUB_HOME is defaulted to $HOME) 30 31 $DOT_GITHUB_HOME/.github/ISSUE_TEMPLATE.md 32 $DOT_GITHUB_HOME/.github/PULL_REQUEST_TEMPLATE.md 33 $DOT_GITHUB_HOME/.github/CONTRIBUTING.md 34 35 You can use Golang's standard template for the template files. 36 Below variables are available by default. 37 38 .IsIssue : (boolean) true when used for issue template 39 .IsPullRequest : (boolean) true when used for pull request template 40 .IsContributing : (boolean) true when used for contributing template 41 .RepoName : (string) repository name 42 .RepoUser : (string) repository owner name 43 44 References: 45 46 GitHub Blog: https://github.com/blog/2111-issue-and-pull-request-templates 47 More usage: https://github.com/rhysd/dot-github#readme 48 Golang template: https://golang.org/pkg/text/template/ 49 50 Flags:` 51 52 func (p *Parsed) ShowUsage(out io.Writer) { 53 fmt.Fprintln(out, Usage) 54 p.flags.SetOutput(out) 55 p.flags.PrintDefaults() 56 } 57 58 func (p *Parsed) ShowVersion(out io.Writer) { 59 fmt.Fprintln(out, "1.2.0") 60 } 61 62 func ParseCmdArgs(err_out io.Writer) (*Parsed, error) { 63 var ( 64 help bool 65 version bool 66 issue bool 67 pr bool 68 contributing bool 69 ) 70 71 flags := flag.NewFlagSet("dot-github", flag.ContinueOnError) 72 flags.SetOutput(err_out) 73 74 flags.BoolVar(&help, "help", false, "Show this help") 75 flags.BoolVar(&version, "version", false, "Show version") 76 flags.BoolVar(&issue, "issue", false, "Import ISSUE_TEMPLATE.md only") 77 flags.BoolVar(&pr, "pullrequest", false, "Import PULL_REQUEST_TEMPLATE.md only") 78 flags.BoolVar(&contributing, "contributing", false, "Import CONTRIBUTING.md only") 79 80 flags.Usage = func() { 81 fmt.Fprintln(err_out, Usage) 82 flags.PrintDefaults() 83 } 84 85 if err := flags.Parse(os.Args[1:]); err != nil { 86 return nil, err 87 } 88 89 return &Parsed{ 90 help, 91 version, 92 issue, 93 pr, 94 contributing, 95 flags, 96 }, nil 97 }