Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd usage: inputFile's default value #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var inputFile *string

func init() {
outputFormat = rootCmd.PersistentFlags().StringP("output", "o", "yaml", "output format: yaml or json")
inputFile = rootCmd.Flags().StringP("file", "f", "-", "file path to neat, or - to read from stdin")
inputFile = rootCmd.Flags().StringP("file", "f", "", "file path to neat, or - to read from stdin")
rootCmd.SetOut(os.Stdout)
rootCmd.SetErr(os.Stderr)
rootCmd.MarkFlagFilename("file")
Expand All @@ -57,6 +57,11 @@ kubectl neat -f ./my-pod.json --output yaml`,
RunE: func(cmd *cobra.Command, args []string) error {
var in, out []byte
var err error

if *inputFile == "" {
return cmd.Help()
}

if *inputFile == "-" {
stdin := cmd.InOrStdin()
in, err = ioutil.ReadAll(stdin)
Expand Down Expand Up @@ -105,19 +110,15 @@ kubectl neat get -- svc -n default myservice --output json`,
kubectlCmd := exec.Command(kubectl, cmdArgs...)
kres, err := kubectlCmd.CombinedOutput()
if err != nil {
return fmt.Errorf("Error invoking kubectl as %v %v", kubectlCmd.Args, err)
return fmt.Errorf("Error invoking kubectl as %v %v\n", kubectlCmd.Args, err)
}
//handle the case of 0--J->J--J
outFormat := *outputFormat
kubeout := "yaml"
for _, arg := range args {
if arg == "json" || arg == "ojson" {
outFormat = "json"
}
}
if !cmd.Flag("output").Changed && kubeout == "json" {
outFormat = "json"
}
Comment on lines -108 to -120
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please explain the purpose of these changes?

out, err = NeatYAMLOrJSON(kres, outFormat)
if err != nil {
return err
Expand Down