<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>emre şahin's digital garden 🍃 - clap_complete</title>
    <link>https://emresahin.net/tags/clap-complete/</link>
    <description>Posts in the clap_complete tag</description>
    <language>en</language>
    <managingEditor>contact@emresahin.net (Emre Şahin)</managingEditor>
    <lastBuildDate>Tue, 15 Sep 2026 19:46:32 +0000</lastBuildDate>
    <atom:link href="https://emresahin.net/tags/clap-complete/rss.xml" rel="self" type="application/rss+xml"/>
    <item>
      <title>devlog 18</title>
      <published>2025-01-28T10:07:28+00:00</published>
      <updated>2025-01-28T10:07:28+00:00</updated>
      <author>Emre Şahin</author>
      <pubDate>Tue, 28 Jan 2025 10:07:28 +0000</pubDate>
      <link>https://emresahin.net/devlog-18/</link>
      <guid isPermaLink="true">https://emresahin.net/devlog-18/</guid>
      <description>🐇 There is no xvc completions command anymore. Let’s remove the test. 🐢 Instead, we can make it test with environment variables for each of these shells. 🐇 It looks like the test fails with wait_status . cargo test -p xvc --test test_completions ... failures: ---- test_completions stdout ---- ......</description>
      <category>devlog</category>
      <category>xvc</category>
      <category>clap</category>
      <category>clap_complete</category>
      <category>testing</category>
      <category>trycmd</category>
      <category>wait_status</category>
      <category>error-handling</category>
      <category>rust</category>
      <content:encoded><![CDATA[<p>🐇 There is no <code>xvc completions</code> command anymore. Let’s remove the test.</p>
<p>🐢 Instead, we can make it test with environment variables for each of these
shells.</p>
<p>🐇 It looks like the test fails with <code>wait_status</code>.</p>
<pre><code class="language-sh">cargo test -p xvc --test test_completions
...
failures:

---- test_completions stdout ----
...
ExitStatus(unix_wait_status(512))

thread 'test_completions' panicked at lib/tests/common/mod.rs:46:5:
Command failed: Command { cmd: "/Users/iex/github.com/iesahin/xvc/target/debug/xvc", stdin: None, timeout: None }
...
</code></pre>
<p>🐢 The failure is in the line:</p>
<pre><code class="language-rust">    let mut cmd = Command::cargo_bin("xvc").unwrap();</code></pre>
<p>So it probably waits for user input to complete, but it doesn’t have any and
cannot complete it, so it returns an error.</p>
<p>🦊 Let’s comment the earlier test out and check if other tests work.</p>
<p>🐢 Yes, they fail the same. When there are no commands to run, xvc returns an
error. Maybe we can change this behavior or handle the error in the
<code>Command::cargo_bin</code> line above.</p>
<p>🐇 I checked the code and we don’t handle the “no arguments” case anywhere. It
looks like the behavior to return an error code is inherited from clap.</p>
<p>🐢 Updated the error handling code to report a more descriptive
message from the source.</p>
<pre><code class="language-sh">cargo test -p xvc --test test_completions
...
failures:

---- test_completions stdout ----
Output { status: ExitStatus(unix_wait_status(25856)), stdout: "", stderr: "\nthread 'main' panicked at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_builder-4.5.20/src/builder/debug_asserts.rs:341:13:\nCommand pipeline: command `export` alias `l` is duplicated\nstack backtrace:\n   0: rust_begin_unwind\n             at /rustc/b1a7dfb91106018f47ed9dc9b27aee1977682868/library/std/src/panicking.rs:692:5\n   1: core::panicking::panic_fmt\n             at /rustc/b1a7dfb91106018f47ed9dc9b27aee1977682868/library/core/src/panicking.rs:75:14\n   2: clap_builder::builder::debug_asserts::assert_app\n             at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_builder-4.5.20/src/builder/debug_asserts.rs:341:13\n   3: clap_builder::builder::command::Command::_build_self\n             at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_builder-4.5.20/src/builder/command.rs:4173:13\n   4: clap_builder::builder::command::Command::_build_recursive\n             at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_builder-4.5.20/src/builder/command.rs:4076:9\n   5: clap_builder::builder::command::Command::_build_recursive\n             at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_builder-4.5.20/src/builder/command.rs:4078:13\n   6: clap_builder::builder::command::Command::build\n             at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_builder-4.5.20/src/builder/command.rs:4071:9\n   7: clap_complete::env::CompleteEnv&lt;F&gt;::try_complete_\n             at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_complete-4.5.40/src/env/mod.rs:229:9\n   8: clap_complete::env::CompleteEnv&lt;F&gt;::try_complete\n             at /Users/iex/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/clap_complete-4.5.40/src/env/mod.rs:210:9\n   9: xvc::main\n             at ./src/main.rs:18:30\n  10: core::ops::function::FnOnce::call_once\n             at... [truncated]
ExitStatus(unix_wait_status(25856))

...

error: test failed, to rerun pass `-p xvc --test test_completions`
</code></pre>
<p>🐢 The real issue is when we assert the successful run, at this line:</p>
<pre><code class="language-rust">            assert!(output.status.success(), "Command failed: {:?}", prepared);</code></pre>
<p>🐇 If you look at the error message carefully, you’ll see that this is a
different error. We added an alias to <code>xvc pipeline export</code> with <code>l</code>, which is
a duplicate.</p>
<p>🐢 Oops, yeah.</p>
<pre><code class="language-sh">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.81s
</code></pre>
<p>🐇 There are some warnings in compilation. Let’s fix these.</p>
<pre><code>cargo build
   Compiling xvc-storage v0.6.14-alpha.8 (/Users/iex/github.com/iesahin/xvc/storage)
   Compiling xvc-file v0.6.14-alpha.8 (/Users/iex/github.com/iesahin/xvc/file)
   Compiling xvc-pipeline v0.6.14-alpha.8 (/Users/iex/github.com/iesahin/xvc/pipeline)
   Compiling xvc v0.6.14-alpha.8 (/Users/iex/github.com/iesahin/xvc/lib)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.28s
</code></pre>
<p>🐢 Finished the build without warnings. Now we can run the whole test suite again.</p>
<p>🐇 Tests are running fine. Updated some error messages and types, and doc tests
also pass. There is an issue with the Rsync storage ref.</p>
<p>🐢 It looks like we try to elide output with <code>[...]</code>, while the proper format is <code>[..]</code>.</p>
<p>🐇 Replaced them with <code>...</code> that will elide multiple lines.</p>
<p>🐢 Pushed changes to the server.</p>]]></content:encoded>
    </item>
    <item>
      <title>devlog 17</title>
      <published>2025-01-27T16:07:11+00:00</published>
      <updated>2025-01-27T16:07:11+00:00</updated>
      <author>Emre Şahin</author>
      <pubDate>Mon, 27 Jan 2025 16:07:11 +0000</pubDate>
      <link>https://emresahin.net/devlog-17/</link>
      <guid isPermaLink="true">https://emresahin.net/devlog-17/</guid>
      <description>🐢 We are progressing towards adding all store completions. In the meantime, I switched to nushell from zsh. Completions for nushell require a different crate and it doesn’t have dynamic completions yet. 🐇 We can just complete the completions for this version and add JSON output for all commands t...</description>
      <category>devlog</category>
      <category>xvc</category>
      <category>clap_complete</category>
      <category>clap</category>
      <category>nushell</category>
      <category>dynamic-completions</category>
      <category>completions</category>
      <category>rust</category>
      <content:encoded><![CDATA[<p>🐢 We are progressing towards adding all store completions. In the meantime, I
switched to nushell from zsh. Completions for
<a href="https://github.com/nushell/nushell">nushell</a> require a different crate and it
doesn’t have dynamic completions yet.</p>
<p>🐇 We can just complete the completions for this version and add JSON output
for all commands to use in nushell. In the meantime, dynamic completions support
for nushell is likely to be added.</p>
<p>🐢 Umm, yep. Then we’ll continue to run tests with zsh for the current version.</p>
<p>🐇 <a href="~/github.com/iesahin/xvc/run-tests.zsh"><code>run-tests</code></a> is a zsh file, and
we will continue to use it. We can switch to nushell eventually as we add more
compatibility with it, but let’s not do this now.</p>
<p>🐢 Where were we the last time for completions?</p>
<p>🐇 We added xvc_path_completers. Let’s check the TODO list now.</p>
<p>🐢 We still need tracked_targets completions in a few places.</p>
<p>🐇 Added those.</p>
<p>🐢 Now we have some strum completers. Let’s finish these up as well.</p>
<p>🐇 Ok. They are done as well.</p>
<p>🐢 Now, let’s start adding a storage_identifier completer. It should read all
<code>XvcStorage</code> records and list their names.</p>
<p>🐇 Added a <code>storage_identifier</code> completer. Let’s add it to all places where we use
storage_identifiers.</p>
<p>🐢 Now, we need completers for pipeline and step names. These are
straightforward.</p>
<p>🐇 Added these. Let’s fill up where they are needed.</p>
<p>🐢 I want to skip some of the fine-grained completions in this version. We can
have a specific completer for <code>--params</code> options for files and params inside,
for example. Or a special completer for directories.</p>
<p>🐇 Let’s not forget these. Reading YAML files and extracting hyperparameter
keys for the prompt would be a really good feature for the user.</p>
<p>🐢 I agree. These are good features in general, but we need to ship the current
version as soon as possible.</p>
<p>🐇 Let’s check the TODO comments once more.</p>
<pre><code class="language-sh">$ rg 'TODO:' 
...
- ✅ pipeline/src/pipeline/api/update.rs:    /// TODO: Add a repository_dirs completer (11:08)
- ✅ file/src/remove/mod.rs:    /// TODO: Add a storage_identifier completer (11:08)
- ✅ file/src/bring/mod.rs:    /// TODO: Add a storage_identifier completer (11:08)
...
</code></pre>
<p>🦊 We can use <code>xvc_path_completer</code> for the tracked directory completer for the
time being. For <code>pipeline update</code>, we can use a <code>ValueHint</code> instead. It’s not
necessary to use a custom completion.</p>
<p>🐢 For the <code>xvc file copy</code> destination, we can have a file or a directory that we
track and is not available, or we don’t track and is available. It’s a similar situation
to xvc_path_completer, but we also need to check the local paths. It requires
some more care.</p>
<p>🐇 Now we can begin to run the tests.</p>
<p>🐢 Is this building?</p>
<p>🐇 It should.</p>
<p>🐢 We also have one bug. xvc shouldn’t print help text when the <code>COMPLETE</code>
environment variable is set.</p>
<p>🐇 Umm, yeah, that’s a blocker.</p>
<p>🐢 Fixed it. We can bump the version and push the changes.</p>]]></content:encoded>
    </item>
    <item>
      <title>devlog 15</title>
      <published>2025-01-20T12:51:56+00:00</published>
      <updated>2025-01-20T12:51:56+00:00</updated>
      <author>Emre Şahin</author>
      <pubDate>Mon, 20 Jan 2025 12:51:56 +0000</pubDate>
      <link>https://emresahin.net/devlog-15/</link>
      <guid isPermaLink="true">https://emresahin.net/devlog-15/</guid>
      <description>🐢 Should we go into completions directly, or do we have anything to update in the working scripts? 🐇 Starting with completions is better. One question I have is whether the completions work for subcommands as usual, like in the static completions. 🐢 Yes, they work. We need to add: source &lt;(COMPLE...</description>
      <category>xvc</category>
      <category>clap</category>
      <category>clap-complete</category>
      <category>zsh</category>
      <category>git</category>
      <category>xvc-file</category>
      <category>xvc-pipeline</category>
      <category>Rust</category>
      <category>refactoring</category>
      <category>CLI design</category>
      <category>feature flags</category>
      <content:encoded><![CDATA[<p>🐢 Should we go into completions directly, or do we have anything to update in the working scripts?</p>
<p>🐇 Starting with completions is better. One question I have is whether the completions work for subcommands as usual, like in the static completions.</p>
<p>🐢 Yes, they work. We need to add:</p>
<pre><code class="language-sh">source &lt;(COMPLETE=zsh xvc)
</code></pre>
<p>to <code>.zshrc</code>, though.</p>
<p>🐇 It looks like we can drop the <code>xvc completions</code> command. We’re just checking the <code>COMPLETE</code> environment variable, and there’s no need for a separate command in this case.</p>
<p>🐢 Yes, let’s remove that.</p>
<p>🐇 Maybe we can employ a <code>completions</code> module for all completion-related functionality. It’s a separate thing, you know.</p>
<p>🐢 Which completions do we need?</p>
<p>🐇 We can just mark them with TODOs now.</p>
<p>🐢 Yes, let’s check where we need completions and what.</p>
<p>🐇 I noticed we’re repeating options in <code>XvcFileCLI</code>, and some of the options are missing, e.g., <code>--from-ref</code> and <code>--to-branch</code>.</p>
<p>🐢 Because it can compile into a different binary, and <code>global</code> options don’t work that way. Maybe we can move all these binaries into different files under <code>lib</code>. We can have feature flags to turn off certain features and compile different binaries.</p>
<p>🦊 Let’s search for it; I haven’t seen it before: building different binaries with feature flags using <code>cargo</code>.</p>
<p>🐢 There is no clear-cut solution, but it looks like we can move all binaries to the root with the <a href="https://rustwiki.org/en/cargo/reference/cargo-targets.html#the-required-features-field"><code>required-features</code></a> field.</p>
<p>🐲 We can postpone this to another release.</p>
<p>🐇 Yes, let’s not spend time on this now.</p>
<p>🐢 Should we try making <code>pipeline_name</code> a global option? It’s repeating everywhere.</p>
<p>🐇 That will make it easier to maintain.</p>
<p>🐢 We’ll have to pass <code>pipeline_name</code> to subcommands, though.</p>
<p>🐇 I think we can have a set of global options that we can pass. For the time being, that’s only the <code>pipeline_name</code>.</p>
<p>🐢 Okay. Let’s do this.</p>
<p>🐇 A similar option is the step name for pipeline steps.</p>
<p>🐢 Dependencies will need a revamp in the next version anyway. So let’s keep it for now.</p>
<p>🐲 Also, the semantics of <code>step-name</code> are different for these commands. <code>step new</code> interprets it as a new name, while <code>step dependency</code> interprets it as an existing name. The first can be renamed to <code>--name</code>, and the second can be <code>--to</code>, as one of its aliases suggests.</p>
<p>🐢 Yes, let’s keep it for now, and we’ll continue to work on others.</p>
<p>🦊 I want to post a comment in the <code>clap</code> discussions.</p>
<p>🐢 Wrote it. Now let’s build it after changing the <code>pipeline_name</code>.</p>
<p>🐇 It compiles. Should we test it?</p>
<p>🐢 I think we’ll test after all this completion work is done.</p>
<p>🐇 We did most of the <code>strum</code>-related completion.</p>
<p>🐢 Didn’t test them yet, though.</p>
<p>🐇 This is Rust. It will work if it compiles, and it compiles.</p>]]></content:encoded>
    </item>
    <item>
      <title>devlog 14</title>
      <published>2025-01-20T10:55:15+00:00</published>
      <updated>2025-01-20T10:55:15+00:00</updated>
      <author>Emre Şahin</author>
      <pubDate>Mon, 20 Jan 2025 10:55:15 +0000</pubDate>
      <link>https://emresahin.net/devlog-14/</link>
      <guid isPermaLink="true">https://emresahin.net/devlog-14/</guid>
      <description>🐢 Now, let’s return to clap and its dynamic completions. Last time you said: 🐇 The examples are only found in the tests: https://github.com/clap-rs/clap/blob/master/clap_complete/tests/testsuite/engine.rs#L604 and we can try to create those random strings this way. 🦊 The issue is that we may not ...</description>
      <category>xvc</category>
      <category>jj</category>
      <category>clap</category>
      <category>clap-complete</category>
      <category>zsh</category>
      <category>gitoxide</category>
      <category>git</category>
      <category>Rust</category>
      <category>dynamic completion</category>
      <category>shell</category>
      <category>development</category>
      <content:encoded><![CDATA[<p>🐢 Now, let’s return to <code>clap</code> and its dynamic completions. Last time you said:</p>
<blockquote>
<p>🐇 The examples are only found in the tests: https://github.com/clap-rs/clap/blob/master/clap_complete/tests/testsuite/engine.rs#L604</p>
</blockquote>
<p>and we can try to create those random strings this way.</p>
<p>🦊 The issue is that we may not be able to use the <code>derive</code> method to add these custom completers. All examples are using the builder API.</p>
<p>🐢 We should be able to obtain the end result from derives and modify them to use these custom completers, but let’s try to use <code>add = ArgValueCompleter</code> first.</p>
<p>🐇 It looks like we have another problem. We need to add a <code>rust-toolchain.toml</code> file to the project, you know, to keep it on the stable channel.</p>
<p>🐢 Ah, yeah, we now use multiple channels. Let’s do that.</p>
<p>🐇 I found <a href="https://docs.rs/clap_complete/latest/clap_complete/engine/struct.ArgValueCompleter.html">an example</a>, actually:</p>
<pre><code class="language-rust">#[derive(Debug, Parser)]
struct Cli {
    #[arg(long, add = ArgValueCompleter::new(custom_completer))]
    custom: Option&lt;String&gt;,
}</code></pre>
<p>🐢 I’m trying to add this to the <code>--from-ref</code> option of Xvc. It’s not running anything. The custom completer should return a random string, but it doesn’t.</p>
<p>🦊 Maybe test with a constant first.</p>
<p>🐢 It didn’t work that way either.</p>
<p>🐇 Let’s do a <code>cargo clean</code>.</p>
<p>🐢 Nothing has changed.</p>
<p>🐇 Let’s take a look at the output of <code>xvc completions</code>:</p>
<pre><code class="language-sh">xvc completions
...
'(--skip-git)--from-ref=[Checkout the given Git reference (branch, tag, commit etc.) before performing the Xvc operation. This runs \`git checkout &lt;given-value&gt;\` before running the command]:FROM_REF:_default' \
...
</code></pre>
<p>🐢 This is the only place <code>--from-ref</code> is mentioned and, as far as I can see, there is nothing that calls a dynamic command here.</p>
<p>🐇 Umm, right. There’s something weird here. Maybe we lack the <code>ArgExt</code> trait or something.</p>
<p>🐢 It should be turned on by <code>clap-complete</code> with its <code>unstable-dynamic</code> feature, but who knows.</p>
<p>🐇 It didn’t work.</p>
<p>🐢 <code>ArgExt</code> is available, but it isn’t being used.</p>
<p>🐇 I think I found the answer in https://jj-vcs.github.io/jj/latest/install-and-setup/#command-line-completion:</p>
<pre><code class="language-sh">source &lt;(COMPLETE=zsh xvc)
</code></pre>
<p>is the command we should use.</p>
<p>🐢 It doesn’t produce a completion script, though.</p>
<p>🐇 We have this in <code>jj/cli/src/cli_util.rs</code>:</p>
<pre><code class="language-rust">        if env::var_os("COMPLETE").is_some() {
            return handle_shell_completion(ui, &amp;self.app, &amp;config, &amp;cwd);
        }</code></pre>
<p>🐢 I think the whole <code>handle_shell_completion</code> set is written by them. I’d like to see what <code>jj</code> with <code>COMPLETE=zsh</code> outputs.</p>
<p>🐇 Building it to see now.</p>
<p>🐢 As expected, it calls a function:</p>
<pre><code class="language-sh">❯ COMPLETE=zsh target/debug/jj
#compdef jj
function _clap_dynamic_completer_jj() {
    local _CLAP_COMPLETE_INDEX=$(expr $CURRENT - 1)
    local _CLAP_IFS=$'\n'

    local completions=("${(@f)$( \
        _CLAP_IFS="$_CLAP_IFS" \
        _CLAP_COMPLETE_INDEX="$_CLAP_COMPLETE_INDEX" \
        COMPLETE="zsh" \
        /Users/iex/github.com/etc/jj/target/debug/jj -- ${words} 2&gt;/dev/null \
    )}")

    if [[ -n $completions ]]; then
        _describe 'values' completions
    fi
}

compdef _clap_dynamic_completer_jj jj
</code></pre>
<p>🐇 Now we should make it the same; the shell must call <code>xvc</code> to get the completions. That’s how all these will work.</p>
<p>🐢 Our goal now is to make a random string output from the <code>--from-ref</code> completion.</p>
<p>🐇 The plan is to make completions work as quickly as possible.</p>
<p>🐢 We have done it. 🎉🥳</p>
<p>🐇 Cool. Now we need to fill up all those completion methods.</p>
<p>🦊 Yeah. We can start with basic ones and move from there.</p>
<p>🐢 There will probably be architectural changes as well. We cannot just run <code>xvc</code> functions directly. We need to run internal functions, but not through commands. At that point, when the user hits tab, we don’t know which command to run.</p>
<p>🐇 Maybe it’s time to move to a Git library. “What is the best Git library for Rust?”</p>
<p>🐲 Should we use a Git library?</p>
<p>🐢 It looks like <a href="https://github.com/GitoxideLabs/gitoxide">Gitoxide</a> is the default Rust way to interact with Git repositories. We can keep our way of using the Git binary and use this as an experimental way to learn.</p>
<p>🦊 Yep. That’s a good idea. We can include it in the lib for the time being and start to use it in completions.</p>]]></content:encoded>
    </item>
    <item>
      <title>devlog 13</title>
      <published>2025-01-19T09:55:05+00:00</published>
      <updated>2025-01-19T09:55:05+00:00</updated>
      <author>Emre Şahin</author>
      <pubDate>Sun, 19 Jan 2025 09:55:05 +0000</pubDate>
      <link>https://emresahin.net/devlog-13/</link>
      <guid isPermaLink="true">https://emresahin.net/devlog-13/</guid>
      <description>🐇 So, what’s next? 🐲 We can work on completions or the GUI. 🐢 Completions are similar to the Homebrew work. It’s in another ecosystem and feels boring. 🐲 We can try to make it in Rust: “Writing shell completions in Rust.” 🐢 There are two solutions: One is clap_complete (https://docs.rs/clap_compl...</description>
      <category>xvc</category>
      <category>completions</category>
      <category>clap_complete</category>
      <category>subcommands</category>
      <category>xvc pipeline step dependency</category>
      <category>xvc aliases</category>
      <category>Rust</category>
      <category>rust-analyzer</category>
      <category>shell completion</category>
      <category>CLI</category>
      <category>auto-save.nvim</category>
      <content:encoded><![CDATA[<p>🐇 So, what’s next?</p>
<p>🐲 We can work on completions or the GUI.</p>
<p>🐢 Completions are similar to the Homebrew work. It’s in another ecosystem and feels boring.</p>
<p>🐲 We can try to make it in Rust: “Writing shell completions in Rust.”</p>
<p>🐢 There are two solutions: One is <code>clap_complete</code> (https://docs.rs/clap_complete/latest/clap_complete/) and the other is <code>shell_completion</code> (https://github.com/JoshMcguigan/shell_completion). The latter is very new but may be what we need: writing completions only with Rust.</p>
<p>🐲 The <code>shell_completion</code> crate is very bare-bones. It doesn’t have anything, actually. https://github.com/JoshMcguigan/shell_completion/issues/1</p>
<p>🐇 The feature that we need is dynamic completion. We’ll write something similar to <a href="https://docs.rs/clap_complete/latest/clap_complete/engine/struct.ArgValueCompleter.html"><code>ArgValueCompleter</code></a> for this.</p>
<p>🦊 I think we can just start a new branch.</p>
<p>🐲 We have a branch for Homebrew; should we merge it?</p>
<p>🐢 I think, yes, we can merge it. We’ll fix it if it breaks. It’s a separate workflow file anyway.</p>
<p>🦊 Created the PR.</p>
<pre><code class="language-sh">ghpl
264	add brew tap	add-brew-tap	OPEN	2025-01-03T05:14:45Z
</code></pre>
<p>🐢 Merged it.</p>
<p>🐇 Now let’s create a new branch and add <code>clap-complete</code> to <code>Cargo.toml</code>.</p>
<p>🐲 There are some packages that we need to take a look at. <code>thiserror</code> now has v2.</p>
<p>🐢 Upgraded packages and compiled. It works.</p>
<p>🐲 Let’s update the version.</p>
<p>🐢 Done. Now we can add <code>clap-complete</code>.</p>
<p>🦊 Added with the <code>unstable-dynamic</code> command. Can we build it again?</p>
<p>🐢 Built it. Now we can add a <code>completions</code> subcommand to Xvc.</p>
<p>🐲 Is this the right name for this?</p>
<p>🐢 It will output a shell script that we can source in the shell.</p>
<p>🐲 Okay, let’s add the subcommand now.</p>
<p>🐢 The example doesn’t work with the <code>clap</code> builder.</p>
<p>🐇 Let’s search for it.</p>
<hr>
<p>🐢 I think we’re extending ourselves a bit when trying to add all dynamic features of completion at once. We can just start by adding completion to <code>xvc-test-helper</code>.</p>
<p>🐇 Yep, that’s a better idea. We can have many more examples, and it’s certainly more straightforward.</p>
<p>🐢 One thing I noticed when working yesterday is that using auto-save was actually preventing many of these swap errors.</p>
<p>🐲 It was a bit slow. Can we take a look at a few others?</p>
<p>🐢 https://github.com/okuuva/auto-save.nvim seems a bit more polished.</p>
<p>🐇 Installed it, but haven’t seen an effect yet.</p>
<p>🐢 We may need to restart this.</p>
<p>🐲 Now, we can get into the <code>test-helper</code> completions.</p>
<p>🐢 Done. Added these quickly as you thought. Now adding this to <code>main</code> seems much easier.</p>
<p>🦊 That was a nice approach. Let’s dive into adding this to <code>main</code>.</p>
<p>🐇 Should we go with a separate command or just an option?</p>
<p>🐲 Our commands have distinct initial letters, allowing them to be used with just those letters. Adding another top-level command for this will make <code>c</code> useless.</p>
<p>🐢 I don’t think that’s a valid concern. We can create aliases for all commands and <code>completions</code> shouldn’t have to have an alias. But I agree that completions should not be a top-level command. It will be run once for installation at most.</p>
<p>🦊 I agree. Let’s call it <code>--completions</code>. It will be run as <code>xvc --completions zsh</code> and will print out the completions.</p>
<p>🐢 Okay. Let’s do this.</p>
<p>🦊 No errors left. Let’s install this version.</p>
<p>🐢 We get:</p>
<pre><code class="language-sh">error: 'xvc' requires a subcommand but one was not provided
  [subcommands: file, init, pipeline, storage, root, check-ignore, aliases, help]

Usage: xvc [OPTIONS] &lt;COMMAND&gt;

For more information, try '--help'.
</code></pre>
<p>🦊 Umm, okay. I think we don’t have an option to create a command like that. Then we’ll have to print completions with a subcommand.</p>
<p>🐲 The above discussion is now moot. ❌</p>
<p>🐢 We can try to push, but probably it’s not worth it.</p>
<p>🐲 Let’s not lose time on this. I think we can remove the <code>aliases</code> command and replace it with <code>completions</code>, and add single-letter aliases to subcommands.</p>
<p>🐢 We can have an option in the <code>completions</code> command to print aliases. That will work.</p>
<p>🦊 I don’t think people will use the <code>aliases</code> command if we have single-letter command aliases.</p>
<p>🐢 You may be right. No need to try to maintain that at this time.</p>
<hr>
<p>🐢 Good morning, and I’m fed up with these <code>blink.cmp</code> errors, you know.</p>
<p>🐇 Reinstalling <code>blink</code> works. It’s interesting to rely on such unreliable software.</p>
<p>🐢 Oh, yeah. It’s <em>interesting</em>. Where were we yesterday?</p>
<p>🐲 We decided to rename the <code>aliases</code> command to <code>completions</code>.</p>
<p>🐇 And waiting for <code>rust-analyzer</code> to complete its analysis.</p>
<p>🐢 Uh, yeah. I see.</p>
<p>🦊 The code itself is very short, actually.</p>
<pre><code class="language-rust">    if let Some(shell) = cli_opts.completions {
        let mut cmd = XvcCLI::command();
        generate(shell, &amp;mut cmd, "xvc", &amp;mut io::stdout());
        return Ok(None);
    }</code></pre>
<p>🐲 We’ll use the <code>output!</code> macro instead of writing to <code>io::stdout()</code>, right?</p>
<p>🐢 Yes, we can rely on the usual output system. It will be slower to create an output thread but shouldn’t matter for outputting a shell script.</p>
<p>🐇 It takes a while for <code>rust-analyzer</code> to scan all the directories, it looks like. When I close the project, it just cannot reload it immediately.</p>
<p>🐢 We can use <code>cargo clean</code> from time to time.</p>
<p>🦊 <code>rust-analyzer</code> finished scanning; let’s try to rename <code>AliasesCLI</code>.</p>
<p>🐲 Let’s keep these here; maybe we’ll need them in our scripts:</p>
<pre><code class="language-sh"># Standard Xvc command aliases for longer commands.
alias xls='xvc file list'
alias pvc='xvc pipeline'
alias fvc='xvc file'
alias xvcf='xvc file'
alias xvcft='xvc file track'
alias xvcfl='xvc file list'
alias xvcfs='xvc file send'
alias xvcfb='xvc file bring'
alias xvcfh='xvc file hash'
alias xvcfco='xvc file checkout'
alias xvcfr='xvc file recheck'
alias xvcp='xvc pipeline'
alias xvcpr='xvc pipeline run'
alias xvcps='xvc pipeline step'
alias xvcpsn='xvc pipeline step new'
alias xvcpsd='xvc pipeline step dependency'
alias xvcpso='xvc pipeline step output'
alias xvcpi='xvc pipeline import'
alias xvcpe='xvc pipeline export'
alias xvcpl='xvc pipeline list'
alias xvcpn='xvc pipeline new'
alias xvcpu='xvc pipeline update'
alias xvcpd='xvc pipeline dag'
alias xvcs='xvc storage'
alias xvcsn='xvc storage new'
alias xvcsl='xvc storage list'
alias xvcsr='xvc storage remove'
</code></pre>
<p>🦊 We can use them when adding single-letter aliases.</p>
<p>🐇 There is a <a href="https://docs.rs/clap_complete/latest/clap_complete/aot/enum.Shell.html#method.from_env"><code>from_env</code></a> method for <code>Shell</code>; will we support it?</p>
<p>🦊 I think we can support it. It’s much easier to use if we omit the shell.</p>
<p>🐲 We had <code>aliases</code> in <code>xvc-core</code>, but we need to access <code>XvcCLI</code> from completions. The completions module must be moved to <code>xvc</code>.</p>
<p>🦊 We added the <code>clap_complete</code> dependency to the <code>xvc-pipeline</code> and <code>xvc-file</code> crates, but I don’t think they are necessary. Let’s remove them now.</p>
<p>🐢 Now only the <code>test-helper</code> and <code>xvc</code> crates have the <code>clap_complete</code> dependency.</p>
<p>🐇 Are we ready to test?</p>
<p>🐢 Completions are working. 🎉</p>
<p>🐲 Now we need to update the docs and doc tests, I believe.</p>
<p>🐢 There are also tests to update.</p>
<p>🐇 Tests are running now. In the meantime, can we take a look at the <code>blink</code> configuration?</p>
<p>🐲 When we removed <code>xvc aliases</code>, we also removed <code>pvc</code>, <code>xls</code>, and other aliases. Maybe we can add these to the docs.</p>
<p>🐢 We can put them in the <code>xvc completions</code> reference for now.</p>
<hr>
<p>🐢 It takes a while for <code>rust-analyzer</code> to finish analyzing the codebase.</p>
<p>🦊 Added aliases for <code>xvc pipeline</code> commands. Do you think we need to repeat root-level flags in <code>xvc-pipeline</code>?</p>
<p>🐢 No need to divert attention, I believe. Also, I still think there is an easier way to do that.</p>
<p>🐇 Okay. Do you think we should add easier subcommands to <code>step</code>? Like, <code>step new</code> becoming <code>xvc p s n</code> instead of <code>xvc p s n</code>? (Wait, that’s the same). I mean, more concise.</p>
<p>🐢 I think we can extend these even to the top-level, but shouldn’t make them visible. It will pollute the help text. We can add <code>xvc fl</code> for <code>file list</code> to avoid the space, but hide these from the help text.</p>
<p>🐲 That’s a good idea, but it will require including sub-crate level modules at the top level. We must test it first.</p>
<p>🐢 Let’s finish up the current changes and release them first.</p>
<p>🐇 By the way, we didn’t add two-letter abbreviations to the <code>xvc storage new</code> subcommands. Do you think we need them?</p>
<p>🐢 When we think about the frequency of these commands, no, I don’t think we need them. Users won’t add a new storage every day.</p>
<p>🐇 By that logic, we shouldn’t need an <code>n</code> for <code>xvc storage new</code>.</p>
<p>🐢 Actually, yeah. Maybe we should remove even <code>s</code>.</p>
<p>🦊 <code>storage list</code> may be useful.</p>
<p>🐢 <code>s</code> is a very common letter, though. We can have other uses for that letter.</p>
<p>🐇  Updating <code>xvc p s dependency</code> options, but it looks like making dependency options subcommands is a better way.</p>
<p>🦊 We didn’t do it because currently we can supply multiple options with a single command. If we go the subcommand route, we’ll have to write all dependencies one by one. Adding multiple subcommands with <code>clap</code> is a bit tricky.</p>
<p>🐢 Umm. Yeah, I see.</p>
<p>🐇 Maybe we can provide a separate command to add multiple dependencies. Like, <code>xvc p s d add 'lines=myfile.csv::10-20; file=myimage.jpg; glob=dir/image-10*'</code></p>
<p>🐲 That looks like the start of a language. We need a parser for those strings. They will be freeform.</p>
<p>🦊 Another option is to keep the current options and add commands with the same names.</p>
<p>🐢 That will be confusing. The user will have both <code>--param</code> and <code>param</code>, and they will work differently.</p>
<p>🐇 We can have an <code>add</code> command that accepts the current options. Parsing will be done by <code>clap</code> just like now, but for a subcommand of <code>dependency</code>.</p>
<p>🐢 The full command will be something like <code>xvc pipeline step --step-name preprocessing dependency add --params 'params.json::batch_size'</code></p>
<p>🐇 With shorter commands, it’s like <code>xvc p s -s preprocessing d a --params 'params.json::batch_size'</code>, and this doesn’t look like <code>ffmpeg</code> monstrosities.</p>
<p>🐲 In any case, this is a backward-incompatible change. This should wait for v0.7 along with ECS changes.</p>
<p>🐢 ECS changes are not user-visible, but these are. Certainly needs a minor version update.</p>
<p>🐇 Then, okay, let’s keep the current ones for this version and think about updating them in a future version.</p>
<p>🐢 Okay. Let’s finish up and we’ll create a separate invisible subcommand to ask questions to the Xvc repo for completions.</p>
<p>🐇 We completed completions for the common command structure. Now, we need a way to show certain info after certain commands. A tab after <code>xvc p r -p</code> should show pipeline names, for example.</p>
<p>🐢 Umm, yeah. And these should be as quick as possible. They shouldn’t check Git or any other things.</p>
<p>🐇 I looked here and there, and the only working example I found is here: https://github.com/clap-rs/clap/blob/master/clap_complete/tests/testsuite/zsh.rs#L248 in <code>clap_complete</code> tests.</p>
<p>🐢 Let’s try to dive in. We can start by cloning the repo, I believe.</p>]]></content:encoded>
    </item>
  </channel>
</rss>
