-
Notifications
You must be signed in to change notification settings - Fork 35
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
🪆 separate behavior into sub-commands, with serve being the default #229
Conversation
Holy crap, @itsrainy. I am so impressed that you were able to find a solution here given that the documentation for this scenario is so lacking. I look forward to digging in and trying to understand the details. Before that, though, I think you raise an excellent point here:
I'd like to tag in @Integralist here to ask about the tradeoffs of ditching backwards compatibility in Viceroy's CLI. I believe that in our docs and such, we describe using We'd have to manage a version transition, but that one-time pain vs the ongoing burden of maintaining such an unusual application of |
👋🏻 re:
This is fine to do, my only request is that the new Viceroy release that breaks backwards compatibility be held off until we have a new CLI release that has this forking logic in place. That said, there will be issues for users who have an older version of the Fastly CLI, as the CLI will still be trying to use the old interface for Viceroy and if the CLI downloads a more recent version of Viceroy where the interface has changed then of course the Fastly CLI users will get an error. I personally don't think that's a big deal because they can just run |
Awesome! Thanks for the added context @Integralist! @acfoltzer after spending a bit more time looking at this, I think it would be useful to be a bit more explicit about the tradeoffs. With this PR as-is, the dev experience going forward would look something like this:
I don't think any of the above are necessarily a problem. If we drop the need for backwards compatibility and start requiring a Some things I could see possibly becoming an issue in the future are:
Given all that, I think the approach I'm leaning towards is keeping backwards compatibility for now and eventually deprecating the requirement for a "default subcommand", maybe by adding an info message to that effect before any actual breaking changes are introduced. That seems cleaner to me than adding logic to the Fastly CLI to accommodate version-specific invocations of Viceroy. Let me know if you feel strongly about this one way or the other once you get a chance to look this over! |
@itsrainy let's go with that for now, with the aim of removing the backwards compat code sometime soon. I appreciate you running down the specifics of the dev experience, I'm mainly worried about doing something that's off the beaten path and might not be possible in the future with Also, because it looks so different from typical |
This reverts commit 98854f0.
Addresses #222.
The structure here is somewhat complex in order to get clap to behave how we want it to. Specifically:
serve
andrun
subcommands, but if neither of those is provided the default behavior should beserve
(to maintain backwards compatibility)serve
mode and some are only valid inrun
modeinput
, that is required regardless of the mode🍽️ set
serve
as the default subcommandThe way that we accomplish having a default subcommand with clap is like this:
serve
in this case)args_conflicts_with_subcommands = true
to our top-level struct, so that those two arguments are mutually exclusiveServeArgs
, andRunArgs
)see the example in the clap documentation and this comment for more context
🤝 specify shared arguments
Normally we would put options that are valid in both modes into our top-level
Opts
struct. This unfortunately doesn't work because we need to specifyargs_conflicts_with_subcommands
in order to get the default-subcommand behavior. So to specify arguments that are valid in both modes without a ton of duplication, we can create another structSharedArgs
and include it as aflatten
ed field on each of our subcommand args structs:🔴 specify
input
as a required argFinally, in order to make one of our shared arguments,
input
, required regardless of the mode we are in we need to:Option<String>
rather than justString
(normally this would mean an arg is optional)required = true
to it.see this comment for some context
📜 other things
quiet
into the verbosity flag and as a result verbosity isn't entirely backwards compatible as-is. In order to make0
meanoff
, I had to bumpinfo
,debug
, andtrace
each up a number. I'm unsure what behavior we would like here (ie. if someone using Viceroy right now is used to seeinginfo
level logs, it would make sense to have that be the default inserve
mode while also providing some way to specifyoff
if they would like)