github.com/crosseyed/versionbump@v1.1.0/internal/usage.go (about) 1 package internal 2 3 import ( 4 "github.com/docopt/docopt-go" 5 ) 6 7 type CliOps struct { 8 File string 9 Checktags bool 10 Major bool 11 Minor bool 12 Patch bool 13 List bool 14 } 15 16 func UsageDefault() *string { 17 usage := ` 18 Usage: 19 versionbump (major|minor|patch) [--checktags] <file> 20 versionbump list <file> 21 22 Options: 23 -h --help Show this screen. 24 --version Show version. 25 -c --checktags Avoid bumping if current version is not tagged. 26 <file> Name of file. 27 major major bump. 28 minor minor bump. 29 patch patch bump. 30 list Show version from file. 31 ` 32 return &usage 33 } 34 35 func Usage(doc *string) *string { 36 if doc != nil { 37 return doc 38 } 39 usage := UsageDefault() 40 return usage 41 } 42 43 func Args(args []string, doc *string, version string) (*CliOps, error) { 44 opts, err := docopt.ParseArgs(*Usage(doc), args, version) // nolint 45 var conf = &CliOps{} 46 err = opts.Bind(conf) 47 App.Errors(err, errUsagePanic) 48 return conf, nil 49 } 50 51 // Error Handler(s) 52 func errUsagePanic(err error) { 53 panic(err) 54 }