xvc 0.7.0

An MLOps tool to manage data files and pipelines on top of Git
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
//! Main CLI interface for Xvc
use std::env::ArgsOs;

use std::ffi::OsString;
use std::path::PathBuf;
use std::str::FromStr;

use crate::comp;
use crate::init;
use crate::XvcRootOpt;

use xvc_core::git_checkout_ref;
use xvc_core::handle_git_automation;

use clap::Parser;

use clap_complete::engine::ArgValueCompleter;

use crossbeam::thread;
use crossbeam_channel::bounded;
use log::LevelFilter;
use std::io;
use xvc_core::types::xvcroot::find_root;
use xvc_core::types::xvcroot::load_xvc_root;
use xvc_core::util::completer::git_branch_completer;
use xvc_core::util::completer::git_reference_completer;
use xvc_core::XvcOutputSender;
use xvc_core::{debug, error, uwr, XvcOutputLine};

use xvc_core::check_ignore;
use xvc_core::root;
use xvc_core::setup_logging;
use xvc_core::AbsolutePath;
use xvc_core::CHANNEL_BOUND;
use xvc_core::{XvcLoadParams, XvcVerbosity};
use xvc_file as file;
use xvc_pipeline as pipeline;
use xvc_storage as storage;

use crate::cli;
use crate::error::{Error, Result};

use git_version::git_version;
const GIT_VERSION: &str = git_version!(
    args = ["--always", "--dirty=modified", "--tags"],
    cargo_prefix = "",
    fallback = "unknown"
);

/// Xvc CLI to manage data and ML pipelines
#[derive(Debug, Parser, Clone)]
#[command(
    rename_all = "kebab-case",
    author,
    version = GIT_VERSION
)]
pub struct XvcCLI {
    /// Output verbosity. Use multiple times to increase the output detail.
    #[arg(long = "verbose", short, action = clap::ArgAction::Count)]
    pub verbosity: u8,

    /// Suppress all output.
    #[arg(long)]
    pub quiet: bool,

    /// Turn on all logging to $TMPDIR/xvc.log
    #[arg(long)]
    pub debug: bool,

    /// Set working directory for the command.
    /// It doesn't create a new shell, or change the directory.
    #[arg(short = 'C', default_value = ".")]
    pub workdir: PathBuf,

    /// Configuration options set from the command line in the form section.key=value
    /// You can use multiple times.
    #[arg(long, short = 'c')]
    config: Option<Vec<String>>,

    /// Ignore system configuration file.
    #[arg(long)]
    pub no_system_config: bool,

    /// Ignore user configuration file.
    #[arg(long)]
    pub no_user_config: bool,

    /// Ignore project configuration file (.xvc/config)
    #[arg(long)]
    pub no_project_config: bool,

    /// Ignore local (gitignored) configuration file (.xvc/config.local)
    #[arg(long)]
    pub no_local_config: bool,

    /// Ignore configuration options obtained from environment variables.
    #[arg(long)]
    pub no_env_config: bool,

    /// Don't run automated Git operations for this command.
    /// If you want to run git commands yourself all the time, you can set `git.auto_commit` and
    /// `git.auto_stage` options in the configuration to False.
    #[arg(long)]
    pub skip_git: bool,

    /// Checkout the given Git reference (branch, tag, commit etc.) before performing the Xvc
    /// operation.
    /// This runs `git checkout <given-value>` before running the command.
    #[arg(
        long,
        conflicts_with("skip_git"),
        add = ArgValueCompleter::new(git_reference_completer))]
    pub from_ref: Option<String>,

    /// If given, create (or checkout) the given branch before committing results of the operation.
    /// This runs `git checkout --branch <given-value>` before committing the changes.
    #[arg(long, conflicts_with("skip_git"), add=ArgValueCompleter::new(git_branch_completer))]
    pub to_branch: Option<String>,

    /// The subcommand to run
    #[command(subcommand)]
    pub command: XvcSubCommand,

    /// The calling command for logging and documentation purposes
    #[arg(skip)]
    pub command_string: String,
}

impl XvcCLI {
    /// Parse the given elements with [clap::Parser::parse_from] and merge them to set
    /// [XvcCLI::command_string].
    pub fn from_str_slice(args: &[&str]) -> Result<Self> {
        let command_string = args.join(" ");
        let parsed = Self::parse_from(args);
        Ok(Self {
            command_string,
            ..parsed
        })
    }

    /// Parse the given elements with [clap::Parser::parse_from] and merge them to set
    /// [XvcCLI::command_string].
    pub fn from_string_slice(args: &[String]) -> Result<Self> {
        let command_string = args.join(" ");
        let parsed = Self::parse_from(args);
        Ok(Self {
            command_string,
            ..parsed
        })
    }

    /// Parse the command line from the result of [`std::env::args_os`].
    /// This updates [XvcCLI::command_string] with the command line.
    pub fn from_args_os(args_os: ArgsOs) -> Result<Self> {
        let args: Vec<OsString> = args_os.collect();
        let args: Vec<String> = args
            .iter()
            .map(|s| s.to_string_lossy().to_string())
            .collect();
        let command_string = args.join(" ");
        let parsed = Self::parse_from(args);
        Ok(Self {
            command_string,
            ..parsed
        })
    }

    /// Collects cli config with -c options along with direct options (like verbosity) to provide
    /// to XvcConfig constructor.
    pub fn consolidate_config_options(&self) -> Vec<String> {
        let mut output = self.config.clone().unwrap_or_default();
        output.push(format!(
            "core.verbosity = {}",
            XvcVerbosity::from(self.verbosity)
        ));
        output.push(format!("core.quiet = {}", self.quiet));

        output
    }
}

// Implement FromStr for XvcCLI

impl FromStr for XvcCLI {
    type Err = Error;

    fn from_str(s: &str) -> Result<Self> {
        let command_string = s.to_owned();
        let args: Vec<String> = s.split(' ').map(|a| a.trim().to_owned()).collect();
        let parsed = Self::parse_from(args);
        Ok(Self {
            command_string,
            ..parsed
        })
    }
}

/// Xvc subcommands
#[derive(Debug, Parser, Clone)]
#[command(rename_all = "kebab-case")]
pub enum XvcSubCommand {
    /// File and directory management commands
    #[command(visible_aliases=&["f"])]
    File(xvc_file::XvcFileCLI),

    /// Pipeline management commands
    #[command(visible_aliases=&["p"])]
    Pipeline(xvc_pipeline::PipelineCLI),

    /// Storage (cloud) management commands
    #[command(visible_aliases=&["s"])]
    Storage(xvc_storage::StorageCLI),

    /// Find the root directory of a project
    #[command(visible_aliases=&["r"])]
    Root(xvc_core::root::RootCLI),

    /// Initialize an Xvc project
    #[command()]
    Init(crate::init::InitCLI),

    /// Check whether files are ignored with `.xvcignore`
    #[command()]
    CheckIgnore(xvc_core::check_ignore::CheckIgnoreCLI),

    /// Completion Helpers
    #[command(name = "_comp")]
    _Comp(crate::comp::CompCLI),
}

/// Runs the supplied xvc command.
pub fn run(args: &[&str]) -> Result<XvcRootOpt> {
    let cli_options = cli::XvcCLI::from_str_slice(args)?;
    dispatch(cli_options)
}

/// Run the supplied command within the optional [XvcRoot]. If xvc_root is None, it will be tried
/// to be loaded from `cli_opts.workdir`.
pub fn dispatch_with_root(cli_opts: cli::XvcCLI, xvc_root_opt: XvcRootOpt) -> Result<XvcRootOpt> {
    // XvcRoot should be kept per repository and shouldn't change directory across runs
    assert!(
        xvc_root_opt.as_ref().is_none()
            || xvc_root_opt
                .as_ref()
                .map(|xvc_root| find_root(&cli_opts.workdir).unwrap() == *xvc_root.absolute_path())
                .unwrap()
    );

    let term_log_level = get_term_log_level(get_verbosity(&cli_opts));

    let xvc_root_opt = thread::scope(move |s| {
        let (output_snd, output_rec) = bounded::<Option<XvcOutputLine>>(CHANNEL_BOUND);

        let output_snd_clone = output_snd.clone();

        let output_thread = s.spawn(move |_| {
            while let Ok(Some(output_line)) = output_rec.recv() {
                // output_str.push_str(&output_line);
                match term_log_level {
                    LevelFilter::Off => match output_line {
                        XvcOutputLine::Output(_) => {}
                        XvcOutputLine::Info(_) => {}
                        XvcOutputLine::Warn(_) => {}
                        XvcOutputLine::Error(_) => {}
                        XvcOutputLine::Panic(m) => panic!("[PANIC] {}", m),
                        XvcOutputLine::Tick(_) => todo!(),
                        XvcOutputLine::Debug(_) => {}
                    },
                    LevelFilter::Error => match output_line {
                        XvcOutputLine::Output(m) => println!("{m}"),
                        XvcOutputLine::Info(_) => {}
                        XvcOutputLine::Warn(_) => {}
                        XvcOutputLine::Error(m) => eprintln!("[ERROR] {}", m),
                        XvcOutputLine::Panic(m) => panic!("[PANIC] {}", m),
                        XvcOutputLine::Tick(_) => todo!(),
                        XvcOutputLine::Debug(_) => {}
                    },
                    LevelFilter::Warn => match output_line {
                        XvcOutputLine::Output(m) => println!("{m}"),
                        XvcOutputLine::Warn(m) => eprintln!("[WARN] {}", m),
                        XvcOutputLine::Error(m) => eprintln!("[ERROR] {}", m),
                        XvcOutputLine::Panic(m) => panic!("[PANIC] {}", m),
                        XvcOutputLine::Info(_) => {}
                        XvcOutputLine::Tick(_) => todo!(),
                        XvcOutputLine::Debug(_) => {}
                    },
                    LevelFilter::Info => match output_line {
                        XvcOutputLine::Output(m) => println!("{m}"),
                        XvcOutputLine::Info(m) => eprintln!("[INFO] {}", m),
                        XvcOutputLine::Warn(m) => eprintln!("[WARN] {}", m),
                        XvcOutputLine::Error(m) => eprintln!("[ERROR] {}", m),
                        XvcOutputLine::Panic(m) => panic!("[PANIC] {}", m),
                        XvcOutputLine::Tick(_) => todo!(),
                        XvcOutputLine::Debug(_) => {}
                    },
                    LevelFilter::Debug => match output_line {
                        XvcOutputLine::Output(m) => println!("{m}"),
                        XvcOutputLine::Info(m) => eprintln!("[INFO] {}", m),
                        XvcOutputLine::Warn(m) => eprintln!("[WARN] {}", m),
                        XvcOutputLine::Error(m) => eprintln!("[ERROR] {}", m),
                        XvcOutputLine::Panic(m) => panic!("[PANIC] {}", m),
                        XvcOutputLine::Tick(_) => todo!(),
                        XvcOutputLine::Debug(m) => eprintln!("[DEBUG] {}", m),
                    },
                    LevelFilter::Trace => match output_line {
                        XvcOutputLine::Output(m) => println!("{m}"),
                        XvcOutputLine::Info(m) => eprintln!("[INFO] {}", m),
                        XvcOutputLine::Warn(m) => eprintln!("[WARN] {}", m),
                        XvcOutputLine::Error(m) => eprintln!("[ERROR] {}", m),
                        XvcOutputLine::Debug(m) => eprintln!("[DEBUG] {}", m),
                        XvcOutputLine::Panic(m) => panic!("[PANIC] {}", m),
                        XvcOutputLine::Tick(_) => todo!(),
                    },
                }
            }
        });

        if let Some(ref xvc_root) = xvc_root_opt {
            if let Some(ref from_ref) = cli_opts.from_ref {
                uwr!(
                    git_checkout_ref(&output_snd, xvc_root, from_ref),
                    output_snd
                );
            }
        }
        let xvc_root_opt_res = s.spawn(move |_| -> Result<XvcRootOpt> {
            let xvc_root_opt = command_matcher(cli_opts.clone(), xvc_root_opt, &output_snd)?;

            match xvc_root_opt {
                Some(ref xvc_root) => {
                    xvc_root.record();
                    if cli_opts.skip_git {
                        debug!(output_snd, "Skipping Git operations");
                    } else {
                        handle_git_automation(
                            &output_snd,
                            xvc_root,
                            cli_opts.to_branch.as_deref(),
                            &cli_opts.command_string,
                        )?;
                    }
                }
                None => {
                    debug!(
                        output_snd,
                        "Xvc is outside of a project, no need to handle Git operations."
                    );
                }
            }
            Ok(xvc_root_opt)
        });

        let xvc_root_opt = xvc_root_opt_res.join().unwrap();
        match &xvc_root_opt {
            Ok(_) => debug!(output_snd_clone, "Command completed successfully."),
            Err(e) => error!(output_snd_clone, "{}", e),
        }
        output_snd_clone.send(None).unwrap();
        output_thread.join().unwrap();

        xvc_root_opt
    })
    .unwrap();

    xvc_root_opt
}

/// Dispatch commands to respective functions in the API
///
/// It sets output verbosity with [XvcCLI::verbosity].
/// Determines configuration sources by filling [XvcConfigInitParams].
/// Tries to create an XvcRoot to determine whether we're inside one.
/// It calls [dispatch_with_root] with an optional root.
///
/// A corresponding function to reuse the same [XvcRoot] object is [test_dispatch].
/// It doesn't recreate the whole configuration and this prevents errors regarding multiple
/// initializations.
pub fn dispatch(cli_opts: cli::XvcCLI) -> Result<XvcRootOpt> {
    let verbosity = get_verbosity(&cli_opts);

    let term_log_level = get_term_log_level(verbosity);

    setup_logging(
        Some(term_log_level),
        if cli_opts.debug {
            Some(LevelFilter::Trace)
        } else {
            None
        },
    );

    let xvc_config_params = get_xvc_config_params(&cli_opts);

    let xvc_root_opt = match load_xvc_root(xvc_config_params) {
        Ok(r) => Some(r),
        Err(e) => {
            e.debug();
            None
        }
    };

    dispatch_with_root(cli_opts, xvc_root_opt)
}

/// Decide configuration sources  from CLI options
pub fn get_xvc_config_params(cli_opts: &XvcCLI) -> XvcLoadParams {
    let xvc_root_dir = find_root(&cli_opts.workdir).ok();
    XvcLoadParams {
        xvc_root_dir,
        current_dir: AbsolutePath::from(&cli_opts.workdir),
        include_system_config: !cli_opts.no_system_config,
        include_user_config: !cli_opts.no_user_config,
        include_project_config: !cli_opts.no_project_config,
        include_local_config: !cli_opts.no_local_config,
        project_config_path: None,
        local_config_path: None,
        include_environment_config: !cli_opts.no_env_config,
        command_line_config: Some(cli_opts.consolidate_config_options()),
    }
}

/// Convert verbosity to log level
pub fn get_term_log_level(verbosity: XvcVerbosity) -> LevelFilter {
    match verbosity {
        XvcVerbosity::Quiet => LevelFilter::Off,
        XvcVerbosity::Default => LevelFilter::Error,
        XvcVerbosity::Warn => LevelFilter::Warn,
        XvcVerbosity::Info => LevelFilter::Info,
        XvcVerbosity::Debug => LevelFilter::Debug,
        XvcVerbosity::Trace => LevelFilter::Trace,
    }
}

/// Convert verbosity value to XvcVerbosity
pub fn get_verbosity(cli_opts: &XvcCLI) -> XvcVerbosity {
    if cli_opts.quiet {
        XvcVerbosity::Quiet
    } else {
        match cli_opts.verbosity {
            0 => XvcVerbosity::Default,
            1 => XvcVerbosity::Warn,
            2 => XvcVerbosity::Info,
            3 => XvcVerbosity::Debug,
            _ => XvcVerbosity::Trace,
        }
    }
}

/// Collect all output from the channel in a string and return
// FIXME: Maybe move to xvc-logging
pub fn collect_output(
    output_rcv: &crossbeam_channel::Receiver<Option<XvcOutputLine>>,
    term_log_level: LevelFilter,
) -> String {
    let mut output_str = String::new();
    while let Ok(Some(output_line)) = output_rcv.recv() {
        // output_str.push_str(&output_line);
        match term_log_level {
            LevelFilter::Off => match output_line {
                XvcOutputLine::Output(_) => {}
                XvcOutputLine::Info(_) => {}
                XvcOutputLine::Warn(_) => {}
                XvcOutputLine::Error(_) => {}
                XvcOutputLine::Panic(m) => output_str.push_str(&format!("[PANIC] {}", m)),
                XvcOutputLine::Tick(_) => todo!(),
                XvcOutputLine::Debug(_) => {}
            },
            LevelFilter::Error => match output_line {
                XvcOutputLine::Output(m) => output_str.push_str(&m),
                XvcOutputLine::Info(_) => {}
                XvcOutputLine::Warn(_) => {}
                XvcOutputLine::Error(m) => output_str.push_str(&format!("[ERROR] {}", m)),
                XvcOutputLine::Panic(m) => output_str.push_str(&format!("[PANIC] {}", m)),
                XvcOutputLine::Tick(_) => todo!(),
                XvcOutputLine::Debug(_) => {}
            },
            LevelFilter::Warn => match output_line {
                XvcOutputLine::Output(m) => output_str.push_str(&m),
                XvcOutputLine::Warn(m) => output_str.push_str(&format!("[WARN] {}", m)),
                XvcOutputLine::Error(m) => output_str.push_str(&format!("[ERROR] {}", m)),
                XvcOutputLine::Panic(m) => output_str.push_str(&format!("[PANIC] {}", m)),
                XvcOutputLine::Info(_) => {}
                XvcOutputLine::Tick(_) => todo!(),
                XvcOutputLine::Debug(_) => {}
            },
            LevelFilter::Info => match output_line {
                XvcOutputLine::Output(m) => output_str.push_str(&m),
                XvcOutputLine::Info(m) => output_str.push_str(&format!("[INFO] {}", m)),
                XvcOutputLine::Warn(m) => output_str.push_str(&format!("[WARN] {}", m)),
                XvcOutputLine::Error(m) => output_str.push_str(&format!("[ERROR] {}", m)),
                XvcOutputLine::Panic(m) => output_str.push_str(&format!("[PANIC] {}", m)),
                XvcOutputLine::Tick(_) => todo!(),
                XvcOutputLine::Debug(_) => {}
            },
            LevelFilter::Debug => match output_line {
                XvcOutputLine::Output(m) => output_str.push_str(&m),
                XvcOutputLine::Info(m) => output_str.push_str(&format!("[INFO] {}", m)),
                XvcOutputLine::Warn(m) => output_str.push_str(&format!("[WARN] {}", m)),
                XvcOutputLine::Error(m) => output_str.push_str(&format!("[ERROR] {}", m)),
                XvcOutputLine::Panic(m) => output_str.push_str(&format!("[PANIC] {}", m)),
                XvcOutputLine::Debug(m) => output_str.push_str(&format!("[DEBUG] {}", m)),
                XvcOutputLine::Tick(_) => todo!(),
            },
            LevelFilter::Trace => match output_line {
                XvcOutputLine::Output(m) => output_str.push_str(&m),
                XvcOutputLine::Info(m) => output_str.push_str(&format!("[INFO] {}", m)),
                XvcOutputLine::Warn(m) => output_str.push_str(&format!("[WARN] {}", m)),
                XvcOutputLine::Error(m) => output_str.push_str(&format!("[ERROR] {}", m)),
                XvcOutputLine::Debug(m) => output_str.push_str(&format!("[DEBUG] {}", m)),
                XvcOutputLine::Panic(m) => output_str.push_str(&format!("[PANIC] {}", m)),
                XvcOutputLine::Tick(_) => todo!(),
            },
        }
    }
    output_str
}

/// Run the given command and return the modified [XvcRoot]
pub fn command_matcher(
    cli_opts: XvcCLI,
    xvc_root_opt: XvcRootOpt,
    output_snd: &XvcOutputSender,
) -> Result<XvcRootOpt> {
    {
        let res_xvc_root_opt: Result<XvcRootOpt> = match cli_opts.command {
            XvcSubCommand::Init(opts) => {
                let use_git = !opts.no_git;
                let xvc_root = init::run(xvc_root_opt.as_ref(), opts)?;

                if use_git {
                    handle_git_automation(
                        output_snd,
                        &xvc_root,
                        cli_opts.to_branch.as_deref(),
                        &cli_opts.command_string,
                    )?;
                }
                Ok(Some(xvc_root))
            }

            // following commands can only be run inside a repository
            XvcSubCommand::Root(opts) => {
                root::run(
                    output_snd,
                    xvc_root_opt
                        .as_ref()
                        .ok_or_else(|| Error::RequiresXvcRepository)?,
                    opts,
                )?;

                Ok(xvc_root_opt)
            }

            XvcSubCommand::File(opts) => {
                file::run(output_snd, xvc_root_opt.as_ref(), opts)?;
                Ok(xvc_root_opt)
            }

            XvcSubCommand::Pipeline(opts) => {
                // FIXME: We can replace this stdin with another channel
                let stdin = io::stdin();
                let input = stdin.lock();
                pipeline::cmd_pipeline(
                    input,
                    output_snd,
                    xvc_root_opt.as_ref().ok_or(Error::RequiresXvcRepository)?,
                    opts,
                )?;
                Ok(xvc_root_opt)
            }

            XvcSubCommand::CheckIgnore(opts) => {
                // FIXME: We can replace this stdin with another channel
                let stdin = io::stdin();
                let input = stdin.lock();

                check_ignore::cmd_check_ignore(
                    input,
                    output_snd,
                    xvc_root_opt.as_ref().ok_or(Error::RequiresXvcRepository)?,
                    opts,
                )?;

                Ok(xvc_root_opt)
            }

            XvcSubCommand::Storage(opts) => {
                let stdin = io::stdin();
                let input = stdin.lock();
                storage::cmd_storage(
                    input,
                    output_snd,
                    xvc_root_opt.as_ref().ok_or(Error::RequiresXvcRepository)?,
                    opts,
                )?;

                Ok(xvc_root_opt)
            }

            XvcSubCommand::_Comp(comp_cli) => {
                comp::run(comp_cli)?;
                Ok(xvc_root_opt)
            }
        };

        let xvc_root_opt = match res_xvc_root_opt {
            Ok(xvc_root_opt) => xvc_root_opt,
            Err(e) => {
                error!(&output_snd, "{}", e);
                None
            }
        };

        if let Some(ref xvc_root) = xvc_root_opt {
            if !cli_opts.skip_git {
                xvc_root.record();
                handle_git_automation(
                    output_snd,
                    xvc_root,
                    cli_opts.to_branch.as_deref(),
                    &cli_opts.command_string,
                    // FIXME: Handle this error more gracefully
                )
                .unwrap();
            }
        }

        Ok(xvc_root_opt)
    }
}