feat(cli): Added --color styling flag to wkg cli#220
Conversation
…epracation warning to existing `wkg wit` commands
This comment was marked as outdated.
This comment was marked as outdated.
--color styling flag to wkg cli
vados-cosmonic
left a comment
There was a problem hiding this comment.
I'm not against using anstyle for this, but what do you think about using tracing w/ tracing_subscriber::fmt's ANSI color layer? That would give us error/warn/info colors, and be more interoperable with tracing in the libs.
I've thought about that as well, when we get to exposing wkg as a lib, I would rather have switch to tracing as a detection layer similar to how cargo's [ that flexibility needs to be built to and should come with a I think for now it makes sense to distinguish between purely human stuff (no tracing wrapper) and things triggered by |
d96658a to
3572fe5
Compare
273bd2e to
8569654
Compare
7751a71 to
467ac5d
Compare
467ac5d to
d620cc7
Compare
vados-cosmonic
left a comment
There was a problem hiding this comment.
Thanks for taking another pass at this, we're almost there.
|
|
||
| [workspace.package] | ||
| edition = "2021" | ||
| edition = "2024" |
There was a problem hiding this comment.
Tried seeing if bumping would resolve previous test failures:
https://github.com/bytecodealliance/wasm-pkg-tools/actions/runs/28563549597/job/84686098906
Updating edition did not fix issues and this is out of scope but a nice to have regardless.
This was actual fix:
wasm-pkg-tools/crates/wasm-pkg-common/Cargo.toml
Lines 18 to 19 in f5ded81
TLDR: resolver 3 (and 2) bleeds wkg feature flags when running cargo test from the workspace.
cargo test -p wasm-pkg-core is not impacted but it is impractical to invoke explicitly all the time - hence "test" feature flag for ergonomics.
There was a problem hiding this comment.
alternative: we can remove the ansi styling completely from the types but regaining functionality (if worth it) will not be feasible short term and the workspace feature bleed will still be a problem for other flags.
There was a problem hiding this comment.
To try and restate the problem here -- was it that cargo test -p wkg (or regular cargo test of the workspace) dependency-unifies to wasm-pkg-core *with* ansi-term-outputenabled, no matter what, because of the dep w/ features at thewkg` level?
If so, IMO I don't think we even need to introduce the test feature, adding cargo test -p wasm-pkg-core --no-default-features or something to CI to make sure it runs without is enough.
We could even pull in something like cargo-hack for CI in the future, but my concern here is more that we just get it covered under test so we can't put out a broken release/merge broken code to main.
It's a style thing but what do you think about defining the dep and it's transitive flag dependencies explicitly in wkg too, but as a default?
I believe the syntax would be something like:
[features]
defaults = ["ansi-term-output"]
ansi-term-output = [ "wasm-pkg-common/ansi-term-output", "wasm-pkg-core/ansi-term-output"]and then we could make the ansi-term output deps optional like the other lib crates (though they are pulled in by default)
If someone for example wanted to build the binary even smaller, for some reason, they could run cargo install wkg --no-default-features and get a non-ansi-term build this way, rather than the dependencies being required.
I think this pattern is pretty well accepted, as far as optional deps go, even for bin crates, but I'm OK if you don't want to do this either.
f5ded81 to
0fe596d
Compare
|
|
||
| [workspace.package] | ||
| edition = "2021" | ||
| edition = "2024" |
There was a problem hiding this comment.
To try and restate the problem here -- was it that cargo test -p wkg (or regular cargo test of the workspace) dependency-unifies to wasm-pkg-core *with* ansi-term-outputenabled, no matter what, because of the dep w/ features at thewkg` level?
If so, IMO I don't think we even need to introduce the test feature, adding cargo test -p wasm-pkg-core --no-default-features or something to CI to make sure it runs without is enough.
We could even pull in something like cargo-hack for CI in the future, but my concern here is more that we just get it covered under test so we can't put out a broken release/merge broken code to main.
It's a style thing but what do you think about defining the dep and it's transitive flag dependencies explicitly in wkg too, but as a default?
I believe the syntax would be something like:
[features]
defaults = ["ansi-term-output"]
ansi-term-output = [ "wasm-pkg-common/ansi-term-output", "wasm-pkg-core/ansi-term-output"]and then we could make the ansi-term output deps optional like the other lib crates (though they are pulled in by default)
If someone for example wanted to build the binary even smaller, for some reason, they could run cargo install wkg --no-default-features and get a non-ansi-term build this way, rather than the dependencies being required.
I think this pattern is pretty well accepted, as far as optional deps go, even for bin crates, but I'm OK if you don't want to do this either.
From a UX perspective, I feel it is important for a default argument set to behave predictably and avoid external dependencies as much as possible (especially for top level subcommands like wasm-pkg-tools/crates/wkg/Cargo.toml Lines 11 to 14 in 23cbf8f I would rather deal with awkward design choices in the margins than rely on callouts & caveats sprinkled everywhere to push the user towards providing a specific set of parameters or lean on external tooling like docker, cargo-hack, bash, or just to scaffold baseline expectations. This is obviously subjective but a user should be surprised with a failure when they run something like |
| into_auth_should_read_docker_registry_credentials(); | ||
| into_auth_should_other_registry_credentials(); | ||
| std::env::remove_var("DOCKER_CONFIG"); | ||
| // NOT-SAFE: this is likely causing race conditions |
There was a problem hiding this comment.
I run into race conditions on darwin arm very often with these tests, @ryan-surname-p have you had the same experience?
There was a problem hiding this comment.
I don't recall having issues with this but that's the fun thing about race conditions I could have just gotten lucky.
That said this is definitely racy which it seems someone has acknowledged above on line 235 as well.
Wrapping it in unsafe does make it much more clear.
There was a problem hiding this comment.
the unsafe was a hard error thanks to the 2024 edition bump!
|
Yeah unfortunately I think how Rust work has our hands tied here, given these facts:
I'd like to have this be really obvious from reading the Cargo.toml. Separately, the As far as what the user (developer) tests/has to configure, there is no actual change here based on what I'm describing, it's purely notational, except for the user losing the ability to build without those features required. Requiring those features without giving an opt out is the same as having it as a default feature, except slightly worse because the user has no way to do a more minimal build. The onus to test both the default build and the minimal build is on us as maintainers IMO -- the average developer need not do it. |
|
@vados-cosmonic thanks for the explanation on #220 (comment) |
|
@mkatychev Oh no worries, the It's funny how every time something just-barely-uncomfortable like this comes up I go search on rust-lang/rust and find some 5+ year old issue where someone is asking for the same thing :) |
|
I think I fell for the classic scope creep trap in this PR, I will revert the core/common changes and merge without the display impls and submit a separate PR |
Added `--color` styling flag to wkg cli:
```sh-session
$ ./target/debug/wkg --help
Usage: wkg [OPTIONS] <COMMAND>
Commands:
...
Options:
--color <WHEN> Controls when to use color [default: auto] [possible values: auto, always, never]
...
```
* Added `warnln!`, `statusln!`, and `helpln!` macros
Added `--color` styling flag to wkg cli:
```sh-session
$ ./target/debug/wkg --help
Usage: wkg [OPTIONS] <COMMAND>
Commands:
...
Options:
--color <WHEN> Controls when to use color [default: auto] [possible values: auto, always, never]
...
```
* Added `warnln!`, `statusln!`, and `helpln!` macros
Added
--colorstyling flag to wkg cli:Added

warnln!,statusln!, andhelpln!(stolen™ from cargo):