-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: first iteration of cli #40
base: master
Are you sure you want to change the base?
Conversation
Hello, thank you so much!
I wouldn't bother then. If unknown arguments (like |
yake/src/main.rs
Outdated
struct Cli { | ||
// -ti, --text_input TEXT Input text, SURROUNDED by single quotes(') | ||
#[arg(conflicts_with = "input_file", long)] | ||
text_input: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be Option<String>
?
If you don't provide text_input you get an error, however if input_file
is provided text_input
could, and should remains unprovided.
Similarly should input_file be Option<PathBuf>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo run -- --help yield " -i, --input-file <INPUT_FILE> " instead of -ti
-ti feel weird though. One letter flag -i
is a better alternative despite the retro-compatibility
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm moving the inputs to a separate struct so we can use clap's required = true and multiple = false.
The new struct will have 2 Options
yake/src/main.rs
Outdated
|
||
// -n, --ngram-size INTEGER Max size of the ngram. | ||
#[arg(short, long)] | ||
ngram_size: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ngram_size
, dedup_function
, dedup_lim
and window_size
are all optional in python yake cli and in this rust implementation thanks to Config::default.
Maybe default values could provide a much easier to use cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great comment. And a point that I have struggled with when designing CLIs with clap.
Where do you put the defaults? The CLI is a single struct that is all the CLI inputs, but then gets transformed into other structs with their own defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words:
when the user looks at the help of ngram_size
, they expect it to be optional.
BUT... it does have a default, i.e. 3
in this codebase.
So do we expect the user to see this 3
? If so we should do
#[arg(short, long, default_value_t = Config::default().ngrams)]
ngram_size: usize
That way the default is shown as
-n, --ngram-size <NGRAM_SIZE> Max size of the ngram [default: 3]
However, if we make it an Option<usize>
:
-n, --ngram-size <NGRAM_SIZE> Max size of the ngram
The default isn't shown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My cent: don't be scared to repeat the defaults, as in such case they will be visible to the user. Which is beautiful and allows tuning parameters. You may do something like this to ensure nobody will forget a field in the future:
impl From<ClapConfig> for Config {
fn from(value: ClapConfig) -> Self {
let ClapConfig { one, two, three } = value; // if ClapConfig has a new field, it has to be added here
// Config has a new field, it has to be added here
Self { ... }
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xamgore I've done something for which the CLI reads the defaults from yake's config, so any changes there propagate now.
yake_rust/Cargo.toml
Outdated
@@ -58,6 +90,7 @@ contractions = "0.5.4" | |||
segtok = "0.1.0" | |||
levenshtein = "1.0.5" | |||
indexmap = "2.7.0" | |||
serde = "1.0.217" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi 😏, @Jeanbouvatt, could you put it under optional serde
feature flag?
It's common for rust community to reduce the burden of dependencies. Like, if I don't need JSON at all, serde won't be compiled.
For that, a crate defines an optional feature, which is kinda synced with the dependency.
- If the feature is manually listed
yake-rust = { version = "...", features = ["ineedjson"] }
- If the crate is listed as a dependency in user's Cargo.toml:
[dependencies] serde = "*"
In any of those two cases, ineedjson
will be turned on, and thus serde
crate will be installed. Even more cfg!(feature = "ineedjson")
will be true
, and #[cfg(feature = "ineedjson")]
macro will include the following code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it is
Hey guys, if you feel like working with forked repository is a burden, @quesurifn can grant you permission for collaborating directly here. |
Co-authored-by: Igor Strebz <[email protected]>
Ok, so we are basically waiting for kristof-mattei#3 being merged and ready to move on |
Set serde optional for yake_rust
In response to #35
Hoping to get some initial conversation started here about how we want to design the CLI.
How close do we want to mirror the original one?
clap
does not support multi-character short args (like-ab
).