|
9 | 9 | git "github.com/go-git/go-git/v5" |
10 | 10 | "github.com/karrick/tparse" |
11 | 11 |
|
| 12 | + "github.com/xeol-io/xeol/cmd/xeol/internal/types" |
12 | 13 | "github.com/xeol-io/xeol/internal/format" |
13 | 14 | ) |
14 | 15 |
|
@@ -99,6 +100,11 @@ func (o *Xeol) AddFlags(flags clio.FlagSet) { |
99 | 100 | "manually set the name of the project being analyzed for xeol.io. If you are running xeol inside a git repository, this will be automatically detected.", |
100 | 101 | ) |
101 | 102 |
|
| 103 | + flags.StringVarP(&o.CommitHash, |
| 104 | + "commit-hash", "", |
| 105 | + "manually set the commit hash of the project being analyzed for xeol.io. If you are running xeol inside a git repository, this will be automatically detected.", |
| 106 | + ) |
| 107 | + |
102 | 108 | flags.StringVarP(&o.APIKey, |
103 | 109 | "api-key", "", |
104 | 110 | "set the API key for xeol.io. When this is set, scans will be uploaded to xeol.io.", |
@@ -149,6 +155,28 @@ func (o *Xeol) parseLookaheadOption() (err error) { |
149 | 155 | return nil |
150 | 156 | } |
151 | 157 |
|
| 158 | +func (o *Xeol) parseProjectAndCommitOption() (err error) { |
| 159 | + if o.APIKey != "" { |
| 160 | + if o.ProjectName == "" { |
| 161 | + return fmt.Errorf("must specify a project name when using --api-key. This is usually inferred automatically when running inside a git repository, but you may also pass it manually with --project-name") |
| 162 | + } |
| 163 | + if err := types.ProjectName(o.ProjectName).IsValid(); err != nil { |
| 164 | + return err |
| 165 | + } |
| 166 | + |
| 167 | + if o.CommitHash == "" { |
| 168 | + return fmt.Errorf("must specify a commit hash when using --api-key. This is usually inferred automatically when running inside a git repository, but you may also pass it manually with --commit-hash") |
| 169 | + } |
| 170 | + if err := types.CommitHash(o.CommitHash).IsValid(); err != nil { |
| 171 | + return err |
| 172 | + } |
| 173 | + } |
| 174 | + return nil |
| 175 | +} |
| 176 | + |
152 | 177 | func (o *Xeol) PostLoad() error { |
153 | | - return o.parseLookaheadOption() |
| 178 | + if err := o.parseLookaheadOption(); err != nil { |
| 179 | + return err |
| 180 | + } |
| 181 | + return o.parseProjectAndCommitOption() |
154 | 182 | } |
0 commit comments