Skip to content

Conversation

@mrodm
Copy link
Contributor

@mrodm mrodm commented Aug 28, 2023

Fixes #1249

This PR adds the required checks and documentation for positional arguments under elastic-package profiles sub-commands.

Followed the same approach as in the example of the cobra documentation: https://umarcor.github.io/cobra/#positional-and-custom-arguments

Updated sub-commands:

  • elastic-package profiles create allowed just 1 argument
  • elastic-package profiles delete allowed just 1 argument
  • elastic-package profiles use allowed just 1 argument
  • elastic-package profiles list no args allowed

Example:

  • New documentation:
 $ elastic-package profiles create -h
Create a new profile

Usage:
  elastic-package profiles create [profile] [flags]

Flags:
      --from string   copy profile from the specified existing profile
  -h, --help          help for create

Global Flags:
  -v, --verbose   verbose mode
  • Add validation to ensure the required positional arguments are set:
 $ elastic-package profiles create
Error: accepts 1 arg(s), received 0

For elastic-package profiles list subcommand, this was not failing previously:

 $ elastic-package profiles list a
+-------------------+---------------------------+----------------+----------------+--------------------------------------------------------+
|       NAME        |       DATE CREATED        |      USER      |    VERSION     |                          PATH                          |
+-------------------+---------------------------+----------------+----------------+--------------------------------------------------------+
| default (current) | 2023-07-04T10:27:59+02:00 | mariorodriguez | f5a280a5-dirty | /home/mariorodriguez/.elastic-package/profiles/default |
+-------------------+---------------------------+----------------+----------------+--------------------------------------------------------+
| other             | 2023-07-25T11:17:46+02:00 | mariorodriguez | a564198e-dirty | /home/mariorodriguez/.elastic-package/profiles/other   |
+-------------------+---------------------------+----------------+----------------+--------------------------------------------------------+

Now, it reports an error if an unknown parameter is set:

 $ elastic-package profiles list a
Error: unknown command "a" for "elastic-package profiles list"

@mrodm mrodm self-assigned this Aug 28, 2023
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

cc @mrodm

@mrodm mrodm marked this pull request as ready for review August 28, 2023 11:24
@mrodm mrodm requested a review from a team August 28, 2023 11:24
Use: "delete",
Use: "delete [profile]",
Short: "Delete a profile",
Args: cobra.ExactArgs(1),
Copy link
Member

Choose a reason for hiding this comment

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

👍 nice, probably we should review all subcommands to check if these options are needed in more places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it looks like it would be good to add those validations in the other sub-commands.

Here it has been added for stack sub-commands too: #1412

@mrodm mrodm merged commit 2b6188d into elastic:main Aug 28, 2023
@mrodm mrodm deleted the add_positional_arguments_profile branch August 28, 2023 16:41
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.

Improve help for command elastic-package profile create

3 participants