github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/cmd/fossa/flags/flags.go (about) 1 package flags 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/urfave/cli" 8 ) 9 10 func Combine(sets ...[]cli.Flag) []cli.Flag { 11 flags := make(map[string]cli.Flag) 12 for _, s := range sets { 13 for _, f := range s { 14 name := f.GetName() 15 prev, ok := flags[name] 16 if ok { 17 if prev == f { 18 continue 19 } else { 20 panic(f) 21 } 22 } else { 23 flags[name] = f 24 } 25 } 26 } 27 28 var combined []cli.Flag 29 for _, f := range flags { 30 combined = append(combined, f) 31 } 32 return combined 33 } 34 35 func Short(name string) string { 36 return fmt.Sprintf("%c, %s", name[0], name) 37 } 38 39 func ShortUpper(name string) string { 40 return fmt.Sprintf("%s, %s", strings.ToUpper(name[:1]), name) 41 } 42 43 func WithAPIFlags(f []cli.Flag) []cli.Flag { 44 return append(f, API...) 45 } 46 47 var ( 48 API = []cli.Flag{EndpointF, TitleF, FetcherF, ProjectF, RevisionF, BranchF, ProjectURLF, JIRAProjectKeyF, LinkF, TeamF} 49 Endpoint = "endpoint" 50 EndpointF = cli.StringFlag{Name: Short(Endpoint), Usage: "the FOSSA server endpoint (default: 'https://app.fossa.com')"} 51 Title = "title" 52 TitleF = cli.StringFlag{Name: Short(Title), Usage: "the title of the FOSSA project. (default: the project name)"} 53 Fetcher = "fetcher" 54 FetcherF = cli.StringFlag{Name: Short(Fetcher), Usage: "type of fetcher to use for fossa. (default: 'custom')"} 55 Project = "project" 56 ProjectF = cli.StringFlag{Name: Short(Project), Usage: "this repository's URL or VCS endpoint (default: VCS remote 'origin')"} 57 Revision = "revision" 58 RevisionF = cli.StringFlag{Name: Short(Revision), Usage: "this repository's current revision hash (default: VCS hash HEAD)"} 59 Branch = "branch" 60 BranchF = cli.StringFlag{Name: Short(Branch), Usage: "this repository's current branch (default: current VCS branch)"} 61 ProjectURL = "project-url" 62 ProjectURLF = cli.StringFlag{Name: ShortUpper(ProjectURL), Usage: "this repository's home page"} 63 JIRAProjectKey = "jira-project-key" 64 JIRAProjectKeyF = cli.StringFlag{Name: Short(JIRAProjectKey), Usage: "this repository's JIRA project key"} 65 Link = "link" 66 LinkF = cli.StringFlag{Name: ShortUpper(Link), Usage: "a link to attach to the current build"} 67 Team = "team" 68 TeamF = cli.StringFlag{Name: ShortUpper(Team), Usage: "this repository's team inside your organization"} 69 ) 70 71 func WithGlobalFlags(f []cli.Flag) []cli.Flag { 72 return append(f, Global...) 73 } 74 75 var ( 76 Global = []cli.Flag{ConfigF, NoAnsiF, DebugF} 77 Config = "config" 78 ConfigF = cli.StringFlag{Name: Short(Config), Usage: "path to config file (default: '.fossa.{yml,yaml}')"} 79 NoAnsi = "no-ansi" 80 NoAnsiF = cli.BoolFlag{Name: NoAnsi, Usage: "do not use interactive mode (ANSI codes)"} 81 Debug = "debug" 82 DebugF = cli.BoolFlag{Name: Debug, Usage: "print debug information to stderr"} 83 ) 84 85 func WithOptions(f []cli.Flag) []cli.Flag { 86 return append(f, Options...) 87 } 88 89 var ( 90 Options = []cli.Flag{OptionF} 91 Option = "option" 92 OptionF = cli.StringSliceFlag{Name: Option, Usage: "set configurable options (format is `key:value` e.g. allow-unresolved:true)"} 93 ) 94 95 func WithReportTemplateFlags(f []cli.Flag) []cli.Flag { 96 return append(f, ReportCmd...) 97 } 98 99 var ( 100 ReportCmd = []cli.Flag{OutputFileF, TemplateF} 101 OutputFile = "output-file" 102 OutputFileF = cli.StringFlag{Name: OutputFile, Value: "-", Usage: "Output file for report"} 103 Template = "template" 104 TemplateF = cli.StringFlag{Name: Template, Usage: "process result via template file prior to sending it to output"} 105 )