Skip to content

Commit 953937b

Browse files
committed
final update
1 parent 25f08a8 commit 953937b

File tree

18 files changed

+126
-198
lines changed

18 files changed

+126
-198
lines changed

vdev/Cargo.lock

+35-70
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vdev/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ atty = "0.2.14"
1313
cached = "0.40.0"
1414
clap = { version = "4.0.18", features = ["derive"] }
1515
clap-verbosity-flag = "2.0.0"
16+
clap_complete = "4.0.5"
1617
confy = "0.5.1"
1718
directories = "4.0.1"
1819
# remove this when stabilized https://doc.rust-lang.org/stable/std/path/fn.absolute.html
1920
dunce = "1.0.3"
20-
env_logger = "0.9.1"
2121
hashlink = { version = "0.8.1", features = ["serde_impl"] }
2222
home = "0.5.4"
2323
indicatif = { version = "0.17.1", features = ["improved_unicode"] }

vdev/src/app.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@ use once_cell::sync::OnceCell;
55
use std::time::Duration;
66
use std::{borrow::Cow, process::Command};
77

8-
use crate::config::{Config, ConfigFile};
8+
use crate::config::Config;
99

1010
static VERBOSITY: OnceCell<LevelFilter> = OnceCell::new();
11-
static CONFIG_FILE: OnceCell<ConfigFile> = OnceCell::new();
1211
static CONFIG: OnceCell<Config> = OnceCell::new();
1312
static PATH: OnceCell<String> = OnceCell::new();
1413

1514
pub fn verbosity() -> &'static LevelFilter {
1615
VERBOSITY.get().expect("verbosity is not initialized")
1716
}
1817

19-
pub fn config_file() -> &'static ConfigFile {
20-
CONFIG_FILE.get().expect("config file is not initialized")
21-
}
22-
2318
pub fn config() -> &'static Config {
2419
CONFIG.get().expect("config is not initialized")
2520
}
@@ -98,17 +93,13 @@ fn render_command(command: &mut Command) -> String {
9893
}
9994

10095
pub fn set_global_verbosity(verbosity: LevelFilter) {
101-
VERBOSITY.set(verbosity).unwrap()
102-
}
103-
104-
pub fn set_global_config_file(config_file: ConfigFile) {
105-
CONFIG_FILE.set(config_file).unwrap()
96+
VERBOSITY.set(verbosity).expect("could not set verbosity")
10697
}
10798

10899
pub fn set_global_config(config: Config) {
109-
CONFIG.set(config).unwrap()
100+
CONFIG.set(config).expect("could not set config")
110101
}
111102

112103
pub fn set_global_path(path: String) {
113-
PATH.set(path).unwrap()
104+
PATH.set(path).expect("could not set path")
114105
}

vdev/src/commands/cli.rs

+11-27
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,34 @@ use anyhow::Result;
22
use clap::{Parser, Subcommand};
33
use clap_verbosity_flag::{InfoLevel, Verbosity};
44

5-
use crate::commands;
6-
75
/// Vector's unified dev tool
86
#[derive(Parser, Debug)]
9-
#[
10-
command(
11-
bin_name = "vdev",
12-
author,
13-
version,
14-
about,
15-
disable_help_subcommand = true,
16-
long_about = None,
17-
)
18-
]
7+
#[command(version, bin_name = "vdev", disable_help_subcommand = true)]
198
pub struct Cli {
209
#[clap(flatten)]
21-
pub(crate) verbose: Verbosity<InfoLevel>,
10+
pub verbose: Verbosity<InfoLevel>,
2211

2312
#[command(subcommand)]
2413
command: Commands,
2514
}
2615

2716
#[derive(Subcommand, Debug)]
2817
enum Commands {
29-
/// Build Vector
30-
Build(commands::build::Cli),
31-
/// Manage the vdev config file
32-
Config(commands::config::cli::Cli),
33-
/// Execute a command within the repository
34-
Exec(commands::exec::Cli),
35-
/// Manage integrations
36-
Int(commands::int::cli::Cli),
37-
/// Collection of useful utilities
38-
Meta(commands::meta::cli::Cli),
39-
/// Show information about the current environment
40-
Status(commands::status::Cli),
41-
/// Execute tests
42-
Test(commands::test::Cli),
18+
Build(super::build::Cli),
19+
Complete(super::complete::Cli),
20+
Config(super::config::cli::Cli),
21+
Exec(super::exec::Cli),
22+
Int(super::int::cli::Cli),
23+
Meta(super::meta::cli::Cli),
24+
Status(super::status::Cli),
25+
Test(super::test::Cli),
4326
}
4427

4528
impl Cli {
4629
pub fn exec(&self) -> Result<()> {
4730
match &self.command {
4831
Commands::Build(cli) => cli.exec(),
32+
Commands::Complete(cli) => cli.exec(),
4933
Commands::Config(cli) => cli.exec(),
5034
Commands::Exec(cli) => cli.exec(),
5135
Commands::Int(cli) => cli.exec(),

vdev/src/commands/complete.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use anyhow::Result;
2+
use clap::{Args, CommandFactory};
3+
use clap_complete::{generate, Shell};
4+
use std::io;
5+
6+
use crate::commands::cli::Cli as RootCli;
7+
8+
/// Display the completion file for a given shell
9+
#[derive(Args, Debug)]
10+
#[command()]
11+
pub struct Cli {
12+
#[arg(value_enum)]
13+
shell: Shell,
14+
}
15+
16+
impl Cli {
17+
pub fn exec(&self) -> Result<()> {
18+
let mut cmd = RootCli::command();
19+
let bin_name = cmd.get_name().to_string();
20+
generate(self.shell, &mut cmd, bin_name, &mut io::stdout());
21+
22+
Ok(())
23+
}
24+
}

vdev/src/commands/config/cli.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use anyhow::Result;
22
use clap::{Args, Subcommand};
33

4-
use crate::commands;
5-
64
/// Manage the vdev config file
75
#[derive(Args, Debug)]
86
#[command()]
@@ -13,10 +11,8 @@ pub struct Cli {
1311

1412
#[derive(Subcommand, Debug)]
1513
enum Commands {
16-
/// Locate the config file
17-
Find(commands::config::find::Cli),
18-
/// Modify the config file
19-
Set(commands::config::set::cli::Cli),
14+
Find(super::find::Cli),
15+
Set(super::set::cli::Cli),
2016
}
2117

2218
impl Cli {

0 commit comments

Comments
 (0)