๐ข Now, the next version will have a --json
output for xvc file list
, we can start working on it or update Readme file?
๐ What about adding at least command completions for nushell?
๐ข Letโs read a bit about clap_complete_nushell
๐ฆ There seems to be a nu-complete
command. Letโs check its documentation.
๐ Nothing found and kagi doesnโt help much either.
๐ข There is a completions document for nushell: https://www.nushell.sh/book/custom_completions.html
๐ There is a tool called carapace to provide completions across shells.
๐ข Its documentation is thin and Iโm not sure if it supports dynamic completions out of the box. I believe instead of adding a carapace setup, we can just write a nushell completion script that will use JSON output from the commands and add some (maybe hidden) utility commands to suport it.
๐ There are a set of example scripts in nushell repo: https://github.com/nushell/nu_scripts/tree/main/custom-completions
๐ข The reason I want to write custom completions for nushell is that it will be an exercise for the scripting language. gh
completions are not that scary as a Bash script.
๐ git
completions are a better example for xvc. They simply run git
whenever necessary. We can start from a static completions command and update this with dynamic completions manually. It will teach a lot.
๐ข I forked the nu_scripts
repo and will add xvc completions script there.
๐ Then letโs begin by adding nushell static completions. Shall we add a command for this?
๐ฆ Reviving the completion command we removed in 0.6.13?
๐ข We shouldnโt list it. We can make a _comp
subcommand for the time being and generate and distribute completions in the repository. When clap_complete_nushell
has the feature parity to provide dynamic completions, we can remove these commands.
๐ What will we use this other than generating completions?
๐ข Maybe dynamic completions can call this as well.
๐ Added nushell static completions to be output using xvc _comp generate-nushell
. Letโs bump up the version to 0.6.15.
cargo set-version 0.6.15-alpha.1
Upgrading xvc from 0.6.14 to 0.6.15-alpha.1
...
DEFAULT
๐ข I noticed we forgot a line in cli command handler that asserts xvc_root_opt.is_some()
and this fails when we run xvc
outside of repositories. We need to release this version quickly.
๐ Oops, now, ok, letโs write a static nushell generator and just release quickly.
๐ฆ Generating completions with
xvc comp generate-nushell
DEFAULT
๐ข Completion command is run with comp
instead of _comp
. Should we rename it?
๐ Renamed it to _comp
. Itโs not hidden but at least we can be sure that it wonโt be misunderstood as a common command.
๐ข Bumping the version again. Now letโs source the generated script and test it.
cargo set-version 0.6.15-alpha.2
Upgrading xvc from 0.6.15-alpha.1 to 0.6.15-alpha.2
...
DEFAULT
๐ฆ Yep, it works. We now have completions for nushell.
๐ข Letโs update completions documentation.
๐ Done. Now, letโs take a look at CI and see what fails.
ghrl | first
โญโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ conclusion โ success โ
โ displayTitle โ Add Nushell completions โ
โ headBranch โ nushell-completions โ
โ url โ https://github.com/iesahin/xvc/actions/runs/13070200765 โ
โฐโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
NU
๐ข It fails because of coverage, not the tests. Codecov says the new code isnโt tested.
๐ The added xvc _comp
command isnโt tested. We can add add a test running those lines and testing if the command outputs a completion script.
๐ข We have a test for completions. We can add a test that runs the lines.
๐ Added a test and bumping up the version.
cargo set-version 0.6.15-alpha.3
Upgrading xvc from 0.6.15-alpha.2 to 0.6.15-alpha.3
...
NU
๐ฆ We can add some more coverage while waiting for the tests.
๐ XvcOutputLine
implementation seems to have no tests. Itโs weird, because we use these everywhere.
๐ข Iโm not sure we use this particular implementations, we just use XvcOutputLine::Info(s)
, not XvcOutputLine::info(s)
anywhere. We can delete these methods actually.
๐ Weโll add JSON output via this particular struct. Can we refactor these to use formatting for JSON, for example? Or use these to output JSON?
๐ฆ We can add a formatter to XvcOutputLine
to output structures.
๐ข The enum is now defined as:
#[derive(Clone, Debug)]
pub enum XvcOutputLine {
/// The output that we should be reporting to user
Output(String),
/// For informational messages
Info(String),
/// For debug output to show the internals of Xvc
Debug(String),
/// Warnings that are against some usual workflows
Warn(String),
/// Errors that interrupts a workflow but may be recoverable
Error(String),
/// Panics that interrupts the workflow and ends the program
/// Note that this doesn't call panic! automatically
Panic(String),
/// Progress bar ticks.
/// Self::Info is also used for Tick(1)
Tick(usize),
}
RUST
Here, these fields can also have a formatter
that will render the string in a particular format. For example the output can be
XvcOutputLine::Output(XvcJsonFormatter, String)
RUST
๐ Iโm not sure this is a good idea. Output
already specifies this string as output. We can have a wrapper instead, like,
struct XvcJsonOutput(Format<XvcStructuredOutput>, XvcStructuredOutput)
RUST
and we can use the supplied format to render XvcStructuredOutput
to an output line with XvcOutputLine::Output
. If we donโt provide output as structured, it will be too much error prone work to convert the current outputs to structured.
๐ฆ The transition will also be gradual. We may not need structured output for most of the commands. We can start with xvc file list
and convert others as we go.
๐ข This is sensible. By the way, coverage still didnโt increase. There may something going on with codecov or running the test.
ghrl | first
โญโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ conclusion โ success โ
โ displayTitle โ Add Nushell completions โ
โ headBranch โ nushell-completions โ
โ url โ https://github.com/iesahin/xvc/actions/runs/13087431038 โ
โฐโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
NU
๐ Letโs run the test:
cargo test -p xvc --test test_completions
...
test test_completions ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.80s
SH
๐ข Can we make sure the output is a nushell script and not an error message?
๐ Letโs print it out.
๐ข It looks when COMPLETE
environment variable is set, it never calls _comp
subcommand and never calls those lines.
cargo set-version 0.6.15-alpha.4
Upgrading xvc from 0.6.15-alpha.3 to 0.6.15-alpha.4
...
DEFAULT
๐ข Letโs make a release for 0.6.15. Coverage is OK now.
cargo set-version 0.6.15
Upgrading xvc from 0.6.15-alpha.4 to 0.6.15
...
NU
gh pr merge --squash --body $"(open CHANGELOG.md | lines | skip 2 | take 5)" --subject "Add static nushell completions"
NU
๐ Merged the PR.
๐ข Releases should appear in a few minutes.
๐ We need to tag the merge commit for this.
๐ข Oh, yep. AFAIK Lazygit doesnโt have something for git push --tags
. Letโs push from the CLI.
git push --tags
You are on the main branch. Skipping CHANGELOG.md check.
To github.com:iesahin/xvc
* [new tag] v0.6.15 -> v0.6.15
NU
๐ฆ These commands, especially tables are not rendered correctly on the web. We need to change the theme I think.