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

Create a dedicated documentation section on StructOpt migration #3422

Closed
2 tasks done
nyurik opened this issue Feb 8, 2022 · 14 comments
Closed
2 tasks done

Create a dedicated documentation section on StructOpt migration #3422

nyurik opened this issue Feb 8, 2022 · 14 comments
Labels
C-enhancement Category: Raise on the bar on expectations

Comments

@nyurik
Copy link
Contributor

nyurik commented Feb 8, 2022

Please complete the following tasks

Clap Version

3.0.14

Describe your use case

Clap has great documentation, but for those migrating from structopt it might be a bit challenging to find all the relevant bits between FAQ, Release notes, and other sources. I have looked at them, including discussions, and they tend to have many unrelated v2->v3 and other details. Release notes tend to get burred over time, especially when not linked directly. Structopt users will always have an unchanged version of structopt (as it is no longer updated) that needs to be migrated. Thanks!

Describe the solution you'd like

Please add a dedicated structopt section to the documentation page that succinctly gives minimum required steps to migrate latest structopt usage to clap v3 (or whatever the latest would be).

Alternatives, if applicable

No response

Additional Context

No response

@nyurik nyurik added the C-enhancement Category: Raise on the bar on expectations label Feb 8, 2022
@epage
Copy link
Member

epage commented Feb 8, 2022

Leaving aside the release notes being buried over time, what were you finding lacking in our migration guide?

  • You mentioned v2->v3 migration but that is necessary because you have to do them together

@nyurik
Copy link
Contributor Author

nyurik commented Feb 8, 2022

@epage I understand that clap migrated v2->v3 and as part of that migration introduced structopt-like functionality (yay!!). My point is that many users who use structopt would not be aware of this migration due to never using clap directly. I just did a (small) migration, and would have found the following information useful. This is by no means complete guide, but I have had to research some of them in several places, so might be useful to others, perhaps as a two column table.

StructOpt Migration Guide

  • In Cargo.toml, replace structopt = "0.3.26" dependency with clap = { version = "3.0.14", features = ["derive"] }
  • Replace use structopt::StructOpt; with use clap::Parser as StructOpt;, or replace all #[derive(StructOpt)] usages with #[derive(Parser)]
  • [Optional] Replace #[structopt(...)] with #[clap(...)] (TBD: I have no idea why both still work, and if its intentional)
  • Replace Opt::from_args() with Opt::parse(), where Opt is the top level options struct.
  • Remove arg_enum! { enum { ... } } wrapper, replacing it with #[derive(ArgEnum)] enum { ... }. At the enum usage in a struct, remove possible_values and case_insensitive structopt params, and use #[clap(arg_enum)] instead.

@epage
Copy link
Member

epage commented Feb 8, 2022

My point is that many users who use structopt would not be aware of this migration due to never using clap directly.

Yes, aside from the question on where it should live or how to discover it, I was trying to understand what you found lacking in our existing migration guide because you alluded to several problems with it.

(TBD: I have no idea why both still work, and if its intentional)

We tried to favor deprecations over hard breaking changes:

  • StructOpt is an alias for Parser
    • #[structopt] maps to #[clap]
  • Parser also includes from_args.
  • arg_enum! still exists

epage added a commit that referenced this issue Feb 8, 2022
epage added a commit to epage/structopt that referenced this issue Feb 8, 2022
clap-rs/clap#3422 drew attention to the lack of discoverability of the
migration guide.  We've added it to the clap FAQ item about structopt.
Adding it here as well in hopes people will find it.
@epage
Copy link
Member

epage commented Feb 8, 2022

I have added a link to our migration guide to our FAQ and have opened a PR to add a link from structopt's README.

@nyurik
Copy link
Contributor Author

nyurik commented Feb 9, 2022

My point is that many users who use structopt would not be aware of this migration due to never using clap directly.

Yes, aside from the question on where it should live or how to discover it, I was trying to understand what you found lacking in our existing migration guide because you alluded to several problems with it.

I think my biggest concern with it is that it is in the release notes vs readme, and so it won't be maintained as an ongoing documentation in a single location. Clap will certainly change with time, but people may decided to migrate from their existing well-working StructOpts at any time, possibly in some future when release notes won't be as up to date.

(TBD: I have no idea why both still work, and if its intentional)

We tried to favor deprecations over hard breaking changes:

  • StructOpt is an alias for Parser
    • #[structopt] maps to #[clap]
  • Parser also includes from_args.
  • arg_enum! still exists

My IDE shows deprecations as crossed-out, so I changed them right away and thought it would be a good idea to include them in the migration guide. I think migration should be done towards the non-deprecated features so as not to revisit them again soon.

Once again, thanks for all the hard work, absolutely love the project, just trying to help newcomers get started quicker :)

@epage
Copy link
Member

epage commented Feb 9, 2022

I think my biggest concern with it is that it is in the release notes vs readme, and so it won't be maintained as an ongoing documentation in a single location. Clap will certainly change with time, but people may decided to migrate from their existing well-working StructOpts at any time, possibly in some future when release notes won't be as up to date.

I was thinking about this and I think it shouldn't be a living document. As we diverge further from clap2, the worse it will be both for the user and for us to document. We also then have to decide at what point in the long tail we cut people off and stop updating it. Instead, I think its best for people to migrate to clap v3 first and then to any future version.

My IDE shows deprecations as crossed-out, so I changed them right away and thought it would be a good idea to include them in the migration guide. I think migration should be done towards the non-deprecated features so as not to revisit them again soon.

It was a very intentional choice to leave deprecations to the end and more as a foot note. There are a lot of subtle behavior changes and we wanted the user to focus on those and not all of the mechanical changes.

TeXitoi pushed a commit to TeXitoi/structopt that referenced this issue Feb 9, 2022
clap-rs/clap#3422 drew attention to the lack of discoverability of the
migration guide.  We've added it to the clap FAQ item about structopt.
Adding it here as well in hopes people will find it.
@epage
Copy link
Member

epage commented Feb 9, 2022

As we have a dedicated migration guide, written to accomplish specific goals, and it is now more discoverable, I'm going to go ahead and close this.

@epage epage closed this as completed Feb 9, 2022
@dmitris
Copy link

dmitris commented Jan 30, 2023

to note the "structopt migration guide" link on https://docs.rs/clap/4.1.4/clap/_faq/index.html#how-does-clap-compare-to-structopt pointing to https://docs.rs/clap/4.1.4/clap/CHANGELOG.md#migrate-structopt is bad/stale ("The requested resource does not exist"). Do you know the current location, by any chance? /cc @epage

@epage
Copy link
Member

epage commented Jan 30, 2023

See https://github.com/clap-rs/clap/blob/v3-master/CHANGELOG.md#migrating

Looks like we link to it from structopt's pinned issue and the README but not docs.rs. That would be a worthwhile improvement.

@Croug
Copy link

Croug commented Jan 4, 2024

I wanted to mention that https://docs.rs/clap/latest/clap/_faq/index.html#how-does-clap-compare-to-structopt still gives bad resource when trying to click on the link to the migration guide, I believe this should be resolved as the faq is always in the first couple links when trying to find information around migrating from structopt to clap derive.

@epage
Copy link
Member

epage commented Jan 4, 2024

... wow they clearly said the link was bad and I somehow overlooked that. The link should be fixed in 4.4.13

@Croug
Copy link

Croug commented Jan 4, 2024

Happens to the best of us 😂, thanks for the quick response!

@RReverser
Copy link

RReverser commented Jan 22, 2024

FWIW the "Documentation parity" link on https://docs.rs/clap/latest/clap/_faq/index.html#how-does-clap-compare-to-structopt is still broken.

@epage
Copy link
Member

epage commented Jan 22, 2024

Missed that one. Not as needed anymore, so I removed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

5 participants