Skip to content

Subcommand path from a top/root context #680

Open

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!

Activity

  1. nckswt commented on Mar 7, 2019

    @nckswt
  2. kdeldycke commented on Aug 26, 2025

    @kdeldycke
    Collaborator

    Related to this discussion, I developed a set of utilities which are introspecting Click CLI and recreate the structure of the commands/groups/parameters tree.

    I am currently relying on that code to automatically mirror a CLI into its configuration file and have an automatic --show-params to introspect a CLI structure.

    This is part of my Click Extra project to improve on Click.

  3. added
    parsingParsing, parameters, commands, chaining, context
    and removed on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    parsingParsing, parameters, commands, chaining, context

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions