mirror of
https://github.com/TeFiLeDo/tree-owners.git
synced 2024-11-24 21:26:17 +01:00
fix cli completion generation
This commit is contained in:
parent
f1de150495
commit
a806fb4de2
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -130,6 +130,15 @@ dependencies = [
|
||||
"terminal_size",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_complete"
|
||||
version = "4.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4110a1e6af615a9e6d0a36f805d5c99099f8bab9b8042f5bc1fa220a4a89e36f"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.4.2"
|
||||
@ -465,6 +474,7 @@ version = "0.1.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"clap_complete",
|
||||
"file-owner",
|
||||
"human-panic",
|
||||
"serde",
|
||||
|
@ -20,3 +20,8 @@ file-owner = "0.1.2"
|
||||
human-panic = "1.2.0"
|
||||
serde = { version = "1.0.188", features = ["derive"] }
|
||||
serde_json = "1.0.107"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.75"
|
||||
clap = { version = "4.4.4", features = ["derive", "cargo", "wrap_help"] }
|
||||
clap_complete = "4.4.1"
|
||||
|
27
build.rs
Normal file
27
build.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use std::{env, fs::create_dir};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use clap::CommandFactory;
|
||||
use clap_complete::{
|
||||
generate_to,
|
||||
shells::{Bash, Fish, Zsh},
|
||||
};
|
||||
|
||||
include!("src/cli.rs");
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let out = if env::var("CI").map(|ci| ci == "true").unwrap_or_default() {
|
||||
create_dir("ci-out").context("failed to create CI output directory")?;
|
||||
"./ci-out".to_string()
|
||||
} else {
|
||||
env::var("OUT_DIR").context("OUT_DIR not set")?
|
||||
};
|
||||
|
||||
println!("cargo:rerun-if-changed=src/cli.rs");
|
||||
let mut cli = <Args as CommandFactory>::command();
|
||||
let _ = generate_to(Fish, &mut cli, env!("CARGO_PKG_NAME"), out.clone());
|
||||
let _ = generate_to(Bash, &mut cli, env!("CARGO_PKG_NAME"), out.clone());
|
||||
let _ = generate_to(Zsh, &mut cli, env!("CARGO_PKG_NAME"), out);
|
||||
|
||||
Ok(())
|
||||
}
|
20
src/cli.rs
Normal file
20
src/cli.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
/// Command line arguments.
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(author, about, version)]
|
||||
pub(crate) struct Args {
|
||||
/// Whether to output data as json.
|
||||
#[clap(long)]
|
||||
pub json: bool,
|
||||
|
||||
/// Whether to output raw uid and gid numbers.
|
||||
#[clap(long)]
|
||||
pub raw: bool,
|
||||
|
||||
/// The roots to use for discovery.
|
||||
#[clap(default_value = ".")]
|
||||
pub roots: Vec<PathBuf>,
|
||||
}
|
26
src/main.rs
26
src/main.rs
@ -1,14 +1,11 @@
|
||||
use std::{
|
||||
fs::read_dir,
|
||||
os::linux::fs::MetadataExt,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
use std::{fs::read_dir, os::linux::fs::MetadataExt, path::Path};
|
||||
|
||||
use anyhow::{ensure, Context, Result};
|
||||
use clap::Parser;
|
||||
|
||||
use crate::{id::Ids, name::Names, output::Output};
|
||||
use crate::{cli::Args, id::Ids, name::Names, output::Output};
|
||||
|
||||
mod cli;
|
||||
mod id;
|
||||
mod name;
|
||||
mod output;
|
||||
@ -35,23 +32,6 @@ fn main() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Command line arguments.
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(author, about, version)]
|
||||
struct Args {
|
||||
/// Whether to output data as json.
|
||||
#[clap(long)]
|
||||
pub json: bool,
|
||||
|
||||
/// Whether to output raw uid and gid numbers.
|
||||
#[clap(long)]
|
||||
pub raw: bool,
|
||||
|
||||
/// The roots to use for discovery.
|
||||
#[clap(default_value = ".")]
|
||||
pub roots: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
/// Perform gid & uid gathering for a file, or a directory and its children.
|
||||
fn fs_entry(entry: &Path, summary: &mut Ids) -> Result<()> {
|
||||
let display = entry.display();
|
||||
|
Loading…
Reference in New Issue
Block a user