Skip to content

Commit 54d0b76

Browse files
Enable creating Input Manifests from the CLI (omnibor#184)
* feat: Refactor and update CLI. Refactor the CLI to be more future-proof, easier to read, and to have improved help text. Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com> * feat: Initial `manifest create` implementation. This is the initial implementation of the `manifest create` subcommand, which allows you to create OmniBOR manifests from the CLI. Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com> * fix: Switch from cache dir to data dir We try to default-infer an OmniBOR root directory if none is specified. In the prior version of this code we'd use the `dirs::cache_dir` function, which doesn't quite get us the right directory. `dirs::data_dir` is more accurately representative of what we want. Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com> * chore: General fixup of the CLI. Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com> * chore: Slight help text cleanup. Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com> * feat: Added `debug config` subcommand. This subcommand helps with debugging the CLI, and will hopefully be useful in the future. Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com> --------- Signed-off-by: Andrew Lilley Brinker <alilleybrinker@gmail.com>
1 parent 0908e3d commit 54d0b76

File tree

14 files changed

+424
-128
lines changed

14 files changed

+424
-128
lines changed

Cargo.toml

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ ci = "github"
2222
# The installers to generate for each app
2323
installers = ["shell", "powershell"]
2424
# Target platforms to build apps for (Rust target-triple syntax)
25-
targets = ["aarch64-apple-darwin", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"]
25+
targets = [
26+
"aarch64-apple-darwin",
27+
"x86_64-apple-darwin",
28+
"x86_64-unknown-linux-gnu",
29+
"x86_64-unknown-linux-musl",
30+
"x86_64-pc-windows-msvc",
31+
]
2632
# Publish jobs to run in CI
2733
pr-run-mode = "plan"
2834
# Whether to install an updater program
@@ -111,14 +117,14 @@ split_commits = false
111117

112118
# regex for parsing and grouping commits
113119
commit_parsers = [
114-
{ message = "^.*: add", group = "Added" },
115-
{ message = "^.*: support", group = "Added" },
116-
{ message = "^.*: remove", group = "Removed" },
117-
{ message = "^.*: delete", group = "Removed" },
118-
{ message = "^test", group = "Fixed" },
119-
{ message = "^fix", group = "Fixed" },
120-
{ message = "^.*: fix", group = "Fixed" },
121-
{ message = "^.*", group = "Changed" },
120+
{ message = "^.*: add", group = "Added" },
121+
{ message = "^.*: support", group = "Added" },
122+
{ message = "^.*: remove", group = "Removed" },
123+
{ message = "^.*: delete", group = "Removed" },
124+
{ message = "^test", group = "Fixed" },
125+
{ message = "^fix", group = "Fixed" },
126+
{ message = "^.*: fix", group = "Fixed" },
127+
{ message = "^.*", group = "Changed" },
122128
]
123129

124130
# protect breaking changes from being skipped due to matching a skipping commit_parser

omnibor-cli/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ path = "src/main.rs"
2828

2929
[dependencies]
3030

31-
omnibor = "0.5.1"
31+
omnibor = { version = "0.5.1", path = "../omnibor" }
3232
anyhow = "1.0.80"
3333
async-walkdir = "1.0.0"
3434
futures-lite = "2.2.0"
3535
serde_json = "1.0.114"
36-
smart-default = "0.7.1"
3736
url = "2.5.0"
3837
tracing = "0.1.40"
3938
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
39+
dirs = "5.0.1"
40+
pathbuf = "1.0.0"
4041

4142
[dependencies.clap]
4243

4344
version = "4.5.1"
44-
features = ["derive"]
45+
features = ["derive", "env", "wrap_help"]
4546

4647
[dependencies.tokio]
4748

omnibor-cli/src/find.rs renamed to omnibor-cli/src/artifact_find.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
1-
//! The `find` command, which finds files by ID.
1+
//! The `artifact find` command, which finds files by ID.
22
3+
use crate::cli::Config;
34
use crate::cli::FindArgs;
45
use crate::cli::SelectedHash;
56
use crate::fs::*;
67
use crate::print::PrinterCmd;
78
use anyhow::Result;
89
use async_walkdir::WalkDir;
910
use futures_lite::stream::StreamExt as _;
10-
use omnibor::ArtifactId;
11-
use omnibor::Sha256;
1211
use tokio::sync::mpsc::Sender;
1312

14-
/// Run the `find` subcommand.
15-
pub async fn run(tx: &Sender<PrinterCmd>, args: &FindArgs) -> Result<()> {
16-
let FindArgs { url, path, format } = args;
13+
/// Run the `artifact find` subcommand.
14+
pub async fn run(tx: &Sender<PrinterCmd>, config: &Config, args: &FindArgs) -> Result<()> {
15+
let FindArgs { aid, path } = args;
1716

18-
// TODO(alilleybrinker): Correctly handle possible future hash formats.
19-
let id = ArtifactId::<Sha256>::try_from_url(url.clone())?;
20-
let url = id.url();
17+
let url = aid.url();
2118

2219
let mut entries = WalkDir::new(path);
2320

2421
loop {
2522
match entries.next().await {
2623
None => break,
27-
Some(Err(e)) => tx.send(PrinterCmd::error(e, *format)).await?,
24+
Some(Err(e)) => tx.send(PrinterCmd::error(e, config.format())).await?,
2825
Some(Ok(entry)) => {
2926
let path = &entry.path();
3027

@@ -36,7 +33,8 @@ pub async fn run(tx: &Sender<PrinterCmd>, args: &FindArgs) -> Result<()> {
3633
let file_url = hash_file(SelectedHash::Sha256, &mut file, path).await?;
3734

3835
if url == file_url {
39-
tx.send(PrinterCmd::find(path, &url, *format)).await?;
36+
tx.send(PrinterCmd::find(path, &url, config.format()))
37+
.await?;
4038
}
4139
}
4240
}

omnibor-cli/src/artifact_id.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! The `artifact id` command, which identifies files.
2+
3+
use crate::cli::Config;
4+
use crate::cli::IdArgs;
5+
use crate::fs::*;
6+
use crate::print::PrinterCmd;
7+
use anyhow::Result;
8+
use tokio::sync::mpsc::Sender;
9+
10+
/// Run the `artifact id` subcommand.
11+
pub async fn run(tx: &Sender<PrinterCmd>, config: &Config, args: &IdArgs) -> Result<()> {
12+
let mut file = open_async_file(&args.path).await?;
13+
14+
if file_is_dir(&file).await? {
15+
id_directory(tx, &args.path, config.format(), config.hash()).await?;
16+
} else {
17+
id_file(tx, &mut file, &args.path, config.format(), config.hash()).await?;
18+
}
19+
20+
Ok(())
21+
}

0 commit comments

Comments
 (0)