question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a way to deprecate argument

See original GitHub issue

Hello,

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 deprecatedcould 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jcornazcommented, Mar 8, 2019

Do you have any examples of popular CLI programs with deprecated option names

gcloud (CLI for using Google Cloud), regulary deprecate CLI subcomands and options. Just CTRL+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 for glcoud. But here is a random deprecated subcommand: https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-lifecycle.html

Jenkins 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.

1reaction
ajaltcommented, May 12, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found