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

Default subcommand with default arguments: Format current directory #641

Open
Xophmeister opened this issue Oct 6, 2023 · 2 comments
Open
Labels
epic: usability-end-users Relates to the usability of Topiary for endusers to use Topiary as a generic "good enough" formatter type: feature request

Comments

@Xophmeister
Copy link
Member

Xophmeister commented Oct 6, 2023

After a conversation with clap's primary author/maintainer, it turns out that the default subcommand flow is possible to express in clap, while maintaining consistent usage text. CLIG makes the good point that defaults block potential future expansion, however there is a compromise in Topiary's case: bare topiary [GLOBAL_OPTS] [FORMAT_OPTS] could be a shortcut for topiary [GLOBAL_OPTS] format [FORMAT_OPTS] . (i.e., recursively format everything we understand in the current directory), which would be the most likely thing a user would want to do.

Doing this will enable a very convenient shortcut, but not prohibit future expansion nor be a breaking change (i.e., wouldn't require another minor release bump).

@ErinvanderVeen ErinvanderVeen added the epic: usability-end-users Relates to the usability of Topiary for endusers to use Topiary as a generic "good enough" formatter label Oct 6, 2023
@shadowcat-mst
Copy link

The other thing I've done for certain applications is to look for a filename with an extension - i.e. 'x.y' will invoke a default subcommand but !/./ won't. Bonus: './x' works by this trivial heuristic for a no-extension file.

This can also be extended to 'lib/foo' working as a file argument, with './lib' working as a directory argument (the ./ disambiguating that it's not a subcommand)

Which of these you'd actually -want- are highly dependent on your use cases, but I've used more than one variation on the above themes in anger and it's worked out pretty well for me in ... at least most cases? About as many as any of my design decisions do, I guess.

@yannham
Copy link
Member

yannham commented Jan 12, 2024

It's just my two cents, but I don't think saving a whole 3 or 6 letters by avoiding fmt/format is very meaningful. Several other popular languages usually have formatting as part of their toolchain, so you have to write a format subcommand anyway - cargo fmt, go fmt, etc. - so it's not like topiary lags behind, and I think explicitness have also its merits. Even if it's not that expensive to have a default subcommand, it's not entirely free either (in the git-stash example, I reckon that the default command is duplicated, as it must appear both as a flatten command and as a normal subcommand).

If I understand the suggestion correctly, you could just do topiary [GLOBAL_OPTS] [FORMAT_OPTS] but not topiary [GLOBAL_OPTS] [FORMAT_OPTS] <file|dir> ? So it's not that the default subcommand is format, the default subcommand is format .? Are we sure that's the most natural invocation (if most of the users actually pass a file argument, then maybe one should make the default subcommand just format with a possible argument, but then we have the conflict issue again).

And what if you do topiary --some-global-opts --some-format-opts visualize some_file.ncl (using format options that don't make sense for visualization)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic: usability-end-users Relates to the usability of Topiary for endusers to use Topiary as a generic "good enough" formatter type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants