-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Refactor CLI code. This is a general refactoring without logic changes; just restructures command files into a module hierarchy to better accomodate addition of future commands and more clearly distinguish common utilities from commands. It also updates imports to be more consistent and compact. Signed-off-by: Andrew Lilley Brinker <[email protected]> * feat: improve logging and provide verbosity control Add the ability to control logging verbosity in the CLI, and simplify the format of log messages to be more compact. Signed-off-by: Andrew Lilley Brinker <[email protected]> * chore: Remove explicit panics. This replaces explicit panics with error logging. Signed-off-by: Andrew Lilley Brinker <[email protected]> * fix: Update test snapshots for verbosity flags. This fixes the snapshot tests to reflect the addition of verbosity flags. Signed-off-by: Andrew Lilley Brinker <[email protected]> * chore: Refactored output mechanics. This introduces a new `CommandOutput` trait, which ensures that any distinct output message supports all formats. Signed-off-by: Andrew Lilley Brinker <[email protected]> --------- Signed-off-by: Andrew Lilley Brinker <[email protected]>
- Loading branch information
1 parent
d8859a7
commit 772a9e6
Showing
27 changed files
with
687 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
omnibor-cli/src/artifact_id.rs → omnibor-cli/src/cmd/artifact/id.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod find; | ||
pub mod id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! The `debug config` command, which helps debug the CLI configuration. | ||
use crate::{ | ||
cli::Config, | ||
error::{Error, Result}, | ||
print::{root_dir::RootDirMsg, PrinterCmd}, | ||
}; | ||
use tokio::sync::mpsc::Sender; | ||
|
||
/// Run the `debug config` subcommand. | ||
pub async fn run(tx: &Sender<PrinterCmd>, config: &Config) -> Result<()> { | ||
let root = config.dir().ok_or(Error::NoRoot)?.to_path_buf(); | ||
|
||
tx.send(PrinterCmd::msg(RootDirMsg { path: root }, config.format())) | ||
.await | ||
.map_err(|_| Error::PrintChannelClose)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod config; |
9 changes: 5 additions & 4 deletions
9
omnibor-cli/src/manifest_add.rs → omnibor-cli/src/cmd/manifest/add.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! The `manifest create` command, which creates manifests. | ||
use crate::{ | ||
cli::{Config, ManifestCreateArgs}, | ||
error::{Error, Result}, | ||
print::PrinterCmd, | ||
}; | ||
use omnibor::{ | ||
embedding::NoEmbed, hashes::Sha256, storage::FileSystemStorage, InputManifestBuilder, | ||
IntoArtifactId, RelationKind, | ||
}; | ||
use tokio::sync::mpsc::Sender; | ||
use tracing::info; | ||
|
||
/// Run the `manifest create` subcommand. | ||
pub async fn run( | ||
_tx: &Sender<PrinterCmd>, | ||
config: &Config, | ||
args: &ManifestCreateArgs, | ||
) -> Result<()> { | ||
let root = config.dir().ok_or_else(|| Error::NoRoot)?; | ||
|
||
info!(root = %root.display()); | ||
|
||
let storage = FileSystemStorage::new(root).map_err(Error::StorageInitFailed)?; | ||
|
||
let mut builder = InputManifestBuilder::<Sha256, NoEmbed, _>::with_storage(storage); | ||
|
||
for input in &args.inputs { | ||
let aid = input.clone().into_artifact_id().map_err(Error::IdFailed)?; | ||
builder | ||
.add_relation(RelationKind::Input, aid) | ||
.map_err(Error::AddRelationFailed)?; | ||
} | ||
|
||
if let Some(built_by) = &args.built_by { | ||
let aid = built_by | ||
.clone() | ||
.into_artifact_id() | ||
.map_err(Error::IdFailed)?; | ||
builder | ||
.add_relation(RelationKind::BuiltBy, aid) | ||
.map_err(Error::AddRelationFailed)?; | ||
} | ||
|
||
builder | ||
.finish(&args.target) | ||
.map_err(Error::ManifestBuildFailed)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod add; | ||
pub mod create; | ||
pub mod remove; |
9 changes: 5 additions & 4 deletions
9
omnibor-cli/src/manifest_remove.rs → omnibor-cli/src/cmd/manifest/remove.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! Defines individual subcommands. | ||
pub mod artifact; | ||
pub mod debug; | ||
pub mod manifest; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//! Error types. | ||
use omnibor::Error as OmniborError; | ||
use std::{io::Error as IoError, path::PathBuf, result::Result as StdResult}; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error("could not identify '{0}'")] | ||
NotIdentifiable(String), | ||
|
||
#[error("could not find root directory")] | ||
NoRoot, | ||
|
||
#[error("failed to initialize file system storage")] | ||
StorageInitFailed(#[source] OmniborError), | ||
|
||
#[error("failed to generate Artifact ID")] | ||
IdFailed(#[source] OmniborError), | ||
|
||
#[error("failed to add relation to Input Manifest")] | ||
AddRelationFailed(#[source] OmniborError), | ||
|
||
#[error("failed to build Input Manifest")] | ||
ManifestBuildFailed(#[source] OmniborError), | ||
|
||
#[error("failed to write to stdout")] | ||
StdoutWriteFailed(#[source] IoError), | ||
|
||
#[error("failed to write to stderr")] | ||
StderrWriteFailed(#[source] IoError), | ||
|
||
#[error("failed walking under directory '{}'", path.display())] | ||
WalkDirFailed { path: PathBuf, source: IoError }, | ||
|
||
#[error("unable to identify file type for '{}'", path.display())] | ||
UnknownFileType { | ||
path: PathBuf, | ||
#[source] | ||
source: IoError, | ||
}, | ||
|
||
#[error("failed to open file '{}'", path.display())] | ||
FileFailedToOpen { | ||
path: PathBuf, | ||
#[source] | ||
source: IoError, | ||
}, | ||
|
||
#[error("failed to get file metadata '{}'", path.display())] | ||
FileFailedMetadata { | ||
path: PathBuf, | ||
#[source] | ||
source: IoError, | ||
}, | ||
|
||
#[error("failed to make Artifact ID for '{}'", path.display())] | ||
FileFailedToId { | ||
path: PathBuf, | ||
#[source] | ||
source: OmniborError, | ||
}, | ||
|
||
#[error("print channel closed")] | ||
PrintChannelClose, | ||
} | ||
|
||
pub type Result<T> = StdResult<T, Error>; |
Oops, something went wrong.