Skip to content

Subcommand path from a top/root context #680

@ivankravets

Description

@ivankravets

I have a blocked issue platformio/platformio-core#349 that depends on ctx.args option that was broken/removed? in Click 6 ( #473 ).

@mitsuhiko proposed to use Click 5 and what I've been doing last year. I don't see any progress on #473 and thought that maybe is something wrong with implementation?

Really, I need ctx.args leftover arguments on TOP level to determine different options from subcomamnds. For example, if deep subcommand supports --json option and developer uses it, I should be "silent" and don't print any info to stdout (planned updates, maintaince operations etc) because it will break final JSON. That is only the one use case.

The questions:

  1. Do you know other approach how to receive a subcommand path from TOP/ROOT context?
  2. How to receive a final context of subcommand having TOP context?

Using sys.argv without parsing will not help me. I have mix of deep commands/sub-commands. for example, pio command1 arg_cmd_1 --option_cmd_1 subcommand arg_cmd_subcommand. How to receive in this case path like [command1, subcommand]?

I see a few other options that requires some refactoring to existing @platformio code and allow to switch to Click 6 and above:

  1. Manually parse sys.argv - isn't good approach
  2. Define custom Click-based Command class for @click.command(cls=MyCommand) where I'll know which command was called.

I use the same approach with MultiCommand as is in this example https://github.com/pallets/click/blob/master/examples/complex/complex/cli.py

What do I mean, is possible to know about deep subcommand in this position https://github.com/pallets/click/blob/master/examples/complex/complex/cli.py#L63 ?

For exampe, complex init --path /dev/null

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions