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

CLI help option in JSON format #23976

Closed
feloy opened this issue Sep 17, 2024 · 2 comments
Closed

CLI help option in JSON format #23976

feloy opened this issue Sep 17, 2024 · 2 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@feloy
Copy link
Contributor

feloy commented Sep 17, 2024

Feature request description

Podman Desktop's issue containers/podman-desktop#5989 proposes to add a free-form field for the user to add any podman create option when creating a container.
To help the validation of the field, and/or to propose a typeahead helping the user discover existing options, it would be nice that Podman Desktop is able to get the list of options, in a formatted way.

Suggest potential solution

Add an option --json or similar option, to get the output of podman <cmd> --help in a JSON format.

For example:

$ podman create --help --json
{
  "short-description": "Create but do not start a container",
  "description": "Creates a new container from the given image or storage and prepares it for running the specified command\n\nThe container ID is then printed to stdout. You can then start it at any time with the podman start <container_id> command. The container will be created with the initial state 'created'.",
  "usage": "podman create [options] IMAGE [COMMAND [ARG...]]",
  "examples": [
    "podman create alpine ls",
    "podman create --annotation HELLO=WORLD alpine ls",
    "podman create -t -i --name myctr alpine ls"
  ],
  "options": [
    { 
      "long": "--add-host",
      "type": "strings",
      "description": "Add a custom host-to-IP mapping (host:ip) (default [])",
    },
    {
      "short": "-a",
      "long": "--attach",
      "type": "strings",
      "description": "Attach to STDIN, STDOUT or STDERR"
    },
    [...]
  ]
}

Have you considered any alternatives?

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

@feloy feloy added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 17, 2024
@Luap99
Copy link
Member

Luap99 commented Sep 17, 2024

--help is parsed and processed directly by the cobra lib so there is really no way to also parse --json in such a case AFAIK. This means we would need to parse the args ourselves which is not very nice.

While it should be possible to generate json of this it is not exactly great either, the cli help is not really consitent. The type field is not defined in any way and can be basically anything so while you could validate some common known types I don't think in general type as field makes a lot of sense.

But most importantly I really do not understand what you would gain from this at all. Sure you could show the field in your gui but it would not map the the actual API request, API != cli. The API doesn't accept --device foo instead you need to send this in the proper json format. The same for any option really so I do not see how this would get you any closer to accepting any option unless you shell out to podman-remote which AFAIK podman-desktop doesn't do for the podman API requests.

@feloy
Copy link
Contributor Author

feloy commented Sep 17, 2024

@Luap99 thanks for your feedback, effectively the options of the CLI are not directly usable for calling the API.
Closing the issue

@feloy feloy closed this as completed Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants