Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

cmd: fix -h handling #827

Closed
wants to merge 1 commit into from
Closed

cmd: fix -h handling #827

wants to merge 1 commit into from

Conversation

eonpatapon
Copy link
Contributor

Fixes cue -h and cue cmd -h parsing.

Closes #723

Change-Id: I1aeafab49fe8630400829ba2b48372d61ad83232

@google-cla google-cla bot added the cla: yes label Mar 12, 2021
@mpvl mpvl requested a review from myitcv March 20, 2021 18:23
@myitcv
Copy link
Contributor

myitcv commented Mar 21, 2021

Thanks for looking at this, @eonpatapon

However, I'm not totally clear this fixes #723. Adding the following testscript test:

# Verify that the various forms of requesting help work

cue help
cmp stdout stdout.golden

cue --help
cmp stdout stdout.golden

cue -h
cmp stdout stdout.golden

-- stdout.golden --
cue evaluates CUE files, an extension of JSON, and sends them
to user-defined commands for processing.

Commands are defined in CUE as follows:

	import "tool/exec"
	command: deploy: {
		exec.Run
		cmd:   "kubectl"
		args:  [ "-f", "deploy" ]
		in:    json.Encode(userValue) // encode the emitted configuration.
	}

cue can also combine the results of http or grpc request with the input
configuration for further processing. For more information on defining commands
run 'cue help cmd' or go to cuelang.org/pkg/cmd.

For more information on writing CUE configuration files see cuelang.org.

Usage:
  cue [command]

Available Commands:
  cmd         run a user-defined shell command
  completion  Generate completion script
  def         print consolidated definitions
  eval        evaluate and print a configuration
  export      output data in a standard format
  fix         rewrite packages to latest standards
  fmt         formats CUE configuration files
  get         add dependencies to the current module
  help        Help about any command
  import      convert other formats to CUE files
  mod         module maintenance
  trim        remove superfluous fields
  version     print CUE version
  vet         validate data

Flags:
  -E, --all-errors   print all available errors
  -h, --help         help for cue
  -i, --ignore       proceed in the presence of errors
  -s, --simplify     simplify output
      --strict       report errors for lossy mappings
      --trace        trace computation
  -v, --verbose      print information about progress

Additional help topics:
  cue commands   user-defined commands
  cue filetypes  supported file types and qualifiers
  cue flags      common flags for composing packages
  cue injection  inject files or values into specific fields for a build
  cue inputs     package list, patterns, and files

Use "cue [command] --help" for more information about a command.

in cmd/cue/cmd/testdata/script/help.txt as part of this change fails with:

            ...
            > cue -h
            [stderr]
            pflag: help requested
            [exit status 1]

Which helps to highlight a suggestion I was going to make with respect to this change: that we should have a testscript test to help ensure things are working as expected 😄

@eonpatapon
Copy link
Contributor Author

eonpatapon commented Mar 22, 2021

Are you sure you are running the correct cue binary ?

With this pr cue -h works as expected

@myitcv
Copy link
Contributor

myitcv commented Mar 22, 2021

Are you sure you are running the correct cue binary ?

It does indeed work. I've no idea what I was testing before. Entirely my bad, apologies :(

Despite my incompetence, I still think we should add that testscript test for completeness: it makes it much clearer to the reader what's going on.

@eonpatapon
Copy link
Contributor Author

Isn't the unit tests enough for this kind of things ?

@myitcv
Copy link
Contributor

myitcv commented Mar 22, 2021

Almost all of cmd/cue is covered by testscript-style tests. The fact that help is not seems to be an anomaly we can usefully fix as part of this change. It also has the benefit as I said of instantly being clear to the reader what exactly is being tested.

Fixes `cue -h` and `cue cmd -h` parsing.

Closes #723

Change-Id: I1aeafab49fe8630400829ba2b48372d61ad83232
@myitcv
Copy link
Contributor

myitcv commented Mar 22, 2021

This looks great, thanks. I've now imported this to Gerrit https://cue-review.googlesource.com/c/cue/+/9081 and will merge from there.

cueckoo pushed a commit that referenced this pull request Mar 22, 2021
Fixes `cue -h` and `cue cmd -h` parsing.

Closes #723

Change-Id: I1aeafab49fe8630400829ba2b48372d61ad83232

Closes #827
#827

GitOrigin-RevId: 30996db
Change-Id: I4370ec8860c47ca79496e24a55ffc3416f8fefcb
@cueckoo cueckoo closed this in 27d305c Mar 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cue -h doesn't show help page
3 participants