Add a way to deprecate argument
See original GitHub issueHello,
First, thanks a lot for this great tool!
In one of my CLI, I decided to change slightly the API and I want to deprecated some options.
It would be nice if this could be supported out of the box by Clikt
.
class MyCommand : CliktCommand() {
val oldFlag by option("--old-api").convert { it.toBoolean() }.deprecated("Use --new-api instead")
val newFlag by option("--new-api").flag()
override fun run() {
if (oldFlag ?: newFlag) println("Hello world")
}
}
Then if one run --old-api true
, the program would not crash, but display a warning message:
WARNING: The option '--old-api' is deprecated: Use --new-api instead
Running --help
could either not show the option at all, or explicitly state it is deprecated.
Eventually deprecated
could take a severity argument (warning or error) where the “error” level would make the program crash with a nice and explicit error message in case the deprecated api has been used.
What do you think?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to deprecate an argument? - Stack Overflow
So, to rename an argument of a function without harming existing function calls, I came up with the following solution, based on the...
Read more >How to deprecate classes, methods, arguments and hooks in ...
If you want to deprecate and remove an unused argument, use func_get_args() or func_num_args() (see example below):
Read more >Easy way to deprecate arguments with argparse - Github-Gist
Easy way to deprecate arguments with argparse. GitHub Gist: instantly share code, notes, and snippets.
Read more >Deprecate functions and arguments — deprecate_soft • lifecycle
Partially deprecate an argument with "foo(arg = 'must be a scalar integer')" . Deprecate anything else with a custom message by wrapping it...
Read more >deprecation — deprecation 2.0.6 documentation
To mark a function or method as deprecated, wrap it in the deprecated() decorator. This does several things for you: The docstring of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
gcloud
(CLI for using Google Cloud), regulary deprecate CLI subcomands and options. JustCTRL+F
“depreacted” here: https://cloud.google.com/sdk/docs/release-notes.awscli
(CLI for using AWS) is no exception. It is harder to find, because their changelog is not as nice as it is forglcoud
. But here is a random deprecated subcommand: https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-lifecycle.htmlJenkins also deprecated few options (like
--spdy
) for a while before removing them completely.I’m sure we can find others. I bet some security CLI like ssh deprecate unsecure options from time to time.
Thanks for the suggestion! I added this in 4bec1458, which is part of the 2.0.0 release.
Docs: https://ajalt.github.io/clikt/options/#deprecating-options