Skip to content

Commit

Permalink
flux diff artifact: Fix and document --path=- which reads from STDIN.
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Forster <[email protected]>
  • Loading branch information
octo committed Aug 8, 2024
1 parent 2cfc9ec commit c95451e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions cmd/flux/diff_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var ErrDiffArtifactChanged = errors.New("the remote and local artifact contents
var diffArtifactCmd = &cobra.Command{
Use: "artifact",
Short: "Diff Artifact",
Long: withPreviewNote(`The diff artifact command computes the diff between the remote OCI artifact and a local directory or file`),
Long: withPreviewNote(`The diff artifact command prints the diff between the remote OCI artifact and a local directory or file`),
Example: `# Check if local files differ from remote
flux diff artifact oci://ghcr.io/stefanprodan/manifests:podinfo:6.2.0 --path=./kustomize`,
RunE: diffArtifactCmdRun,
Expand All @@ -62,7 +62,7 @@ func newDiffArtifactArgs() diffArtifactFlags {
}

func init() {
diffArtifactCmd.Flags().StringVar(&diffArtifactArgs.path, "path", "", "path to the directory where the Kubernetes manifests are located")
diffArtifactCmd.Flags().StringVar(&diffArtifactArgs.path, "path", "", "path to the directory or file containing the Kubernetes manifests, or '-' to read from STDIN")
diffArtifactCmd.Flags().StringVar(&diffArtifactArgs.creds, "creds", "", "credentials for OCI registry in the format <username>[:<password>] if --provider is generic")
diffArtifactCmd.Flags().Var(&diffArtifactArgs.provider, "provider", sourceOCIRepositoryArgs.provider.Description())
diffArtifactCmd.Flags().StringSliceVar(&diffArtifactArgs.ignorePaths, "ignore-paths", excludeOCI, "set paths to ignore in .gitignore format")
Expand All @@ -85,10 +85,6 @@ func diffArtifactCmdRun(cmd *cobra.Command, args []string) error {
return err
}

if _, err := os.Stat(diffArtifactArgs.path); err != nil {
return fmt.Errorf("invalid path '%s', must point to an existing directory or file", diffArtifactArgs.path)
}

ctx, cancel := context.WithTimeout(context.Background(), rootArgs.timeout)
defer cancel()

Expand Down Expand Up @@ -183,7 +179,7 @@ func loadLocal(path string) (ytbx.InputFile, error) {

sb, err := os.Stat(path)
if err != nil {
return ytbx.InputFile{}, fmt.Errorf("os.Stat(%q): %w", path, err)
return ytbx.InputFile{}, err
}

if sb.IsDir() {
Expand Down

0 comments on commit c95451e

Please sign in to comment.