Skip to content

Commit

Permalink
Resolve linter warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Franssen <marco.franssen@philips.com>
  • Loading branch information
marcofranssen committed Nov 30, 2021
1 parent 29db98e commit cf2d451
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmd/slsa-provenance/cli/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package cli
import (
"fmt"

"github.com/spf13/cobra"

"github.com/philips-labs/slsa-provenance-action/cmd/slsa-provenance/cli/options"
"github.com/philips-labs/slsa-provenance-action/lib/github"
"github.com/spf13/cobra"
)

// Files creates an instance of *cobra.Command to manage file provenance
Expand Down
3 changes: 3 additions & 0 deletions cmd/slsa-provenance/cli/options/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ func RequiredFlagError(flagName string) error {
return fmt.Errorf("no value found for required flag: %s", flagName)
}

// FilesOptions Commandline flags used for the generate files command.
type FilesOptions struct {
GenerateOptions
ArtifactPath string
}

// GetArtifactPath The file(s) or directory of artifacts to include in provenance.
func (o *FilesOptions) GetArtifactPath() (string, error) {
if o.ArtifactPath == "" {
return "", RequiredFlagError("artifact-path")
}
return o.ArtifactPath, nil
}

// AddFlags Registers the flags with the cobra.Command.
func (o *FilesOptions) AddFlags(cmd *cobra.Command) {
o.GenerateOptions.AddFlags(cmd)
cmd.PersistentFlags().StringVar(&o.ArtifactPath, "artifact-path", "", "The file(s) or directory of artifacts to include in provenance.")
Expand Down
8 changes: 7 additions & 1 deletion cmd/slsa-provenance/cli/options/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"github.com/philips-labs/slsa-provenance-action/lib/intoto"
)

// GenerateOptions Commandline flags used for the generate command.
type GenerateOptions struct {
GitHubContext string
RunnerContext string
OutputPath string
ExtraMaterials []string
}

// GetGitHubContext The '${github}' context value, retrieved in a GitHub workflow.
func (o *GenerateOptions) GetGitHubContext() (*github.Context, error) {
if o.GitHubContext == "" {
return nil, RequiredFlagError("github-context")
Expand All @@ -29,6 +31,7 @@ func (o *GenerateOptions) GetGitHubContext() (*github.Context, error) {
return &gh, nil
}

// GetRunnerContext The '${runner}' context value, retrieved in a GitHub workflow.
func (o *GenerateOptions) GetRunnerContext() (*github.RunnerContext, error) {
if o.RunnerContext == "" {
return nil, RequiredFlagError("runner-context")
Expand All @@ -40,13 +43,15 @@ func (o *GenerateOptions) GetRunnerContext() (*github.RunnerContext, error) {
return &runner, nil
}

func (o *FilesOptions) GetOutputPath() (string, error) {
// GetOutputPath The location to write the provenance file.
func (o *GenerateOptions) GetOutputPath() (string, error) {
if o.OutputPath == "" {
return "", RequiredFlagError("output-path")
}
return o.OutputPath, nil
}

// GetExtraMaterials Additional material files to be used when generating provenance.
func (o *GenerateOptions) GetExtraMaterials() ([]intoto.Item, error) {
var materials []intoto.Item

Expand All @@ -72,6 +77,7 @@ func (o *GenerateOptions) GetExtraMaterials() ([]intoto.Item, error) {
return materials, nil
}

// AddFlags Registers the flags with the cobra.Command.
func (o *GenerateOptions) AddFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&o.GitHubContext, "github-context", "", "The '${github}' context value.")
cmd.PersistentFlags().StringVar(&o.RunnerContext, "runner-context", "", "The '${runner}' context value.")
Expand Down
11 changes: 4 additions & 7 deletions cmd/slsa-provenance/cli/options/github-release.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,30 @@ import (
"github.com/spf13/cobra"
)

// GitHubReleaseOptions Commandline flags used for the generate command.
type GitHubReleaseOptions struct {
GenerateOptions
ArtifactPath string
TagName string
}

// GetArtifactPath The location to store the GitHub Release artifact
func (o *GitHubReleaseOptions) GetArtifactPath() (string, error) {
if o.ArtifactPath == "" {
return "", RequiredFlagError("artifact-path")
}
return o.ArtifactPath, nil
}

func (o *GitHubReleaseOptions) GetOutputPath() (string, error) {
if o.ArtifactPath == "" {
return "", RequiredFlagError("output-path")
}
return o.OutputPath, nil
}

// GetTagName The name of the GitHub tag/release
func (o *GitHubReleaseOptions) GetTagName() (string, error) {
if o.TagName == "" {
return "", RequiredFlagError("tag-name")
}
return o.TagName, nil
}

// AddFlags Registers the flags with the cobra.Command.
func (o *GitHubReleaseOptions) AddFlags(cmd *cobra.Command) {
o.GenerateOptions.AddFlags(cmd)
cmd.PersistentFlags().StringVar(&o.ArtifactPath, "artifact-path", "", "The file(s) or directory of artifacts to include in provenance.")
Expand Down
2 changes: 2 additions & 0 deletions cmd/slsa-provenance/cli/options/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"github.com/spf13/cobra"
)

// RootOptions Commandline flags used for the root command.
type RootOptions struct {
Verbose bool
}

// AddFlags Registers the flags with the cobra.Command.
func (o *RootOptions) AddFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&o.Verbose, "verbose", "d", false, "show verbose output")
}

0 comments on commit cf2d451

Please sign in to comment.