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

govc: fix host.esxcli runtime error occurred when no arguments specified #2961

Merged
merged 1 commit into from
Oct 5, 2022

Conversation

Syuparn
Copy link
Contributor

@Syuparn Syuparn commented Oct 2, 2022

Description

This PR fixes govc host.esxcli runtime error occurred when no arguments specified.

Closes: #2960

Type of change

Please mark options that are relevant:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • This change requires a documentation update
  • Build related change

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. If applicable, please also list any relevant
details for your test configuration.

  • run commands below
$ ./govc host.esxcli
./govc: no argument

Checklist:

  • My code follows the CONTRIBUTION guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

@@ -71,6 +72,10 @@ func (cmd *esxcli) Process(ctx context.Context) error {
}

func (cmd *esxcli) Run(ctx context.Context, f *flag.FlagSet) error {
if len(f.Args()) == 0 {
return errors.New("no argument")
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @Syuparn , but could you change to flag.ErrHelp? That's what we do in most commands as it will output the full help text for the command. I think there's a few commands using errors.New we should probably change to flag.ErrHelp. Can also use f.NArg here:

	if f.NArg() == 0 {
		return flag.ErrHelp
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dougm
I changed this to print help message as you suggested.

./govc host.esxcli
Usage: ./govc host.esxcli [OPTIONS] COMMAND [ARG]...

Invoke esxcli command on HOST.

Output is rendered in table form when possible, unless disabled with '-hints=false'.

Examples:
  govc host.esxcli network ip connection list
  govc host.esxcli system settings advanced set -o /Net/GuestIPHack -i 1
  govc host.esxcli network firewall ruleset set -r remoteSerialPort -e true
  govc host.esxcli network firewall set -e false
  govc host.esxcli hardware platform get

Options:
  -cert=                              Certificate [GOVC_CERTIFICATE]
  -dc=                                Datacenter [GOVC_DATACENTER]
  -debug=false                        Store debug logs [GOVC_DEBUG]
  -dump=false                         Enable Go output
  -hints=true                         Use command info hints when formatting output
  -host=                              Host system [GOVC_HOST]
  -host.dns=                          Find host by FQDN
  -host.ip=                           Find host by IP address
  -host.ipath=                        Find host by inventory path
  -host.uuid=                         Find host by UUID
  -json=false                         Enable JSON output
  -k=true                             Skip verification of server certificate [GOVC_INSECURE]
  -key=                               Private key [GOVC_PRIVATE_KEY]
  -persist-session=true               Persist session to disk [GOVC_PERSIST_SESSION]
  -tls-ca-certs=                      TLS CA certificates file [GOVC_TLS_CA_CERTS]
  -tls-known-hosts=                   TLS known hosts file [GOVC_TLS_KNOWN_HOSTS]
  -trace=false                        Write SOAP/REST traffic to stderr
  -u=https://user@127.0.0.1:8989/sdk  ESX or vCenter URL [GOVC_URL]
  -verbose=false                      Write request/response data to stderr
  -vim-namespace=vim25                Vim namespace [GOVC_VIM_NAMESPACE]
  -vim-version=7.0                    Vim version [GOVC_VIM_VERSION]
  -xml=false                          Enable XML output

Closes: vmware#2960
Signed-off-by: syuparn <s.hello.spagetti@gmail.com>
Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

Thanks @Syuparn

@dougm dougm merged commit 634e88f into vmware:master Oct 5, 2022
@Syuparn Syuparn deleted the issue-2960 branch October 5, 2022 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] govc host.esxcli crashes when no arguments are specified
2 participants