mirror of
https://github.com/TeFiLeDo/tree-owners.git
synced 2024-11-25 05:36:15 +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",
|
"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]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.4.2"
|
version = "4.4.2"
|
||||||
@ -465,6 +474,7 @@ version = "0.1.1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_complete",
|
||||||
"file-owner",
|
"file-owner",
|
||||||
"human-panic",
|
"human-panic",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -20,3 +20,8 @@ file-owner = "0.1.2"
|
|||||||
human-panic = "1.2.0"
|
human-panic = "1.2.0"
|
||||||
serde = { version = "1.0.188", features = ["derive"] }
|
serde = { version = "1.0.188", features = ["derive"] }
|
||||||
serde_json = "1.0.107"
|
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::{
|
use std::{fs::read_dir, os::linux::fs::MetadataExt, path::Path};
|
||||||
fs::read_dir,
|
|
||||||
os::linux::fs::MetadataExt,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{ensure, Context, Result};
|
use anyhow::{ensure, Context, Result};
|
||||||
use clap::Parser;
|
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 id;
|
||||||
mod name;
|
mod name;
|
||||||
mod output;
|
mod output;
|
||||||
@ -35,23 +32,6 @@ fn main() -> Result<()> {
|
|||||||
Ok(())
|
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.
|
/// Perform gid & uid gathering for a file, or a directory and its children.
|
||||||
fn fs_entry(entry: &Path, summary: &mut Ids) -> Result<()> {
|
fn fs_entry(entry: &Path, summary: &mut Ids) -> Result<()> {
|
||||||
let display = entry.display();
|
let display = entry.display();
|
||||||
|
Loading…
Reference in New Issue
Block a user