-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/ledger-signing
- Loading branch information
Showing
26 changed files
with
756 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,44 @@ | ||
use clap::command; | ||
|
||
use super::super::super::config::locator; | ||
use crate::commands::config::data; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Config(#[from] locator::Error), | ||
#[error(transparent)] | ||
Data(#[from] data::Error), | ||
} | ||
|
||
#[derive(Debug, clap::Parser, Clone)] | ||
#[group(skip)] | ||
pub struct Cmd { | ||
#[command(flatten)] | ||
pub config_locator: locator::Args, | ||
|
||
#[arg(long, short = 'l')] | ||
pub long: bool, | ||
} | ||
|
||
impl Cmd { | ||
pub fn run(&self) -> Result<(), Error> { | ||
let res = if self.long { self.ls_l() } else { self.ls() }?.join("\n"); | ||
println!("{res}"); | ||
Ok(()) | ||
} | ||
|
||
pub fn ls(&self) -> Result<Vec<String>, Error> { | ||
Ok(data::list_ulids()? | ||
.iter() | ||
.map(ToString::to_string) | ||
.collect()) | ||
} | ||
|
||
pub fn ls_l(&self) -> Result<Vec<String>, Error> { | ||
Ok(data::list_actions()? | ||
.iter() | ||
.map(ToString::to_string) | ||
.collect()) | ||
} | ||
} |
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,30 @@ | ||
use clap::Parser; | ||
|
||
pub mod ls; | ||
pub mod read; | ||
|
||
#[derive(Debug, Parser)] | ||
pub enum Cmd { | ||
/// List cached actions (transactions, simulations) | ||
Ls(ls::Cmd), | ||
/// Read cached action | ||
Read(read::Cmd), | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Ls(#[from] ls::Error), | ||
#[error(transparent)] | ||
Read(#[from] read::Error), | ||
} | ||
|
||
impl Cmd { | ||
pub fn run(&self) -> Result<(), Error> { | ||
match self { | ||
Cmd::Ls(cmd) => cmd.run()?, | ||
Cmd::Read(cmd) => cmd.run()?, | ||
}; | ||
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,39 @@ | ||
use std::{fs, io, path::PathBuf}; | ||
|
||
use super::super::super::config::locator; | ||
use crate::commands::config::data; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Config(#[from] locator::Error), | ||
#[error(transparent)] | ||
Data(#[from] data::Error), | ||
#[error("failed to find cache entry {0}")] | ||
NotFound(String), | ||
#[error(transparent)] | ||
SerdeJson(#[from] serde_json::Error), | ||
} | ||
|
||
#[derive(Debug, clap::Parser, Clone)] | ||
#[group(skip)] | ||
pub struct Cmd { | ||
/// ID of the cache entry | ||
#[arg(long)] | ||
pub id: String, | ||
} | ||
|
||
impl Cmd { | ||
pub fn run(&self) -> Result<(), Error> { | ||
let file = self.file()?; | ||
tracing::debug!("reading file {}", file.display()); | ||
let mut file = fs::File::open(file).map_err(|_| Error::NotFound(self.id.clone()))?; | ||
let mut stdout = io::stdout(); | ||
let _ = io::copy(&mut file, &mut stdout); | ||
Ok(()) | ||
} | ||
|
||
pub fn file(&self) -> Result<PathBuf, Error> { | ||
Ok(data::actions_dir()?.join(&self.id).with_extension("json")) | ||
} | ||
} |
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,30 @@ | ||
use std::{fs, io::ErrorKind}; | ||
|
||
use super::super::config::locator; | ||
use crate::commands::config::data; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Config(#[from] locator::Error), | ||
#[error(transparent)] | ||
Data(#[from] data::Error), | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
} | ||
|
||
#[derive(Debug, clap::Parser, Clone)] | ||
#[group(skip)] | ||
pub struct Cmd {} | ||
|
||
impl Cmd { | ||
pub fn run(&self) -> Result<(), Error> { | ||
let binding = data::project_dir()?; | ||
let dir = binding.data_dir(); | ||
match fs::remove_dir_all(dir) { | ||
Err(err) if err.kind() == ErrorKind::NotFound => (), | ||
r => r?, | ||
} | ||
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,38 @@ | ||
use clap::Parser; | ||
|
||
pub mod actionlog; | ||
pub mod clean; | ||
pub mod path; | ||
|
||
#[derive(Debug, Parser)] | ||
pub enum Cmd { | ||
/// Delete the cache | ||
Clean(clean::Cmd), | ||
/// Show the location of the cache | ||
Path(path::Cmd), | ||
/// Access details about cached actions like transactions, and simulations. | ||
/// (Experimental. May see breaking changes at any time.) | ||
#[command(subcommand)] | ||
Actionlog(actionlog::Cmd), | ||
} | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Clean(#[from] clean::Error), | ||
#[error(transparent)] | ||
Path(#[from] path::Error), | ||
#[error(transparent)] | ||
Actionlog(#[from] actionlog::Error), | ||
} | ||
|
||
impl Cmd { | ||
pub fn run(&self) -> Result<(), Error> { | ||
match self { | ||
Cmd::Clean(cmd) => cmd.run()?, | ||
Cmd::Path(cmd) => cmd.run()?, | ||
Cmd::Actionlog(cmd) => cmd.run()?, | ||
}; | ||
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,21 @@ | ||
use super::super::config::locator; | ||
use crate::commands::config::data; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Config(#[from] locator::Error), | ||
#[error(transparent)] | ||
Data(#[from] data::Error), | ||
} | ||
|
||
#[derive(Debug, clap::Parser, Clone)] | ||
#[group(skip)] | ||
pub struct Cmd {} | ||
|
||
impl Cmd { | ||
pub fn run(&self) -> Result<(), Error> { | ||
println!("{}", data::data_local_dir()?.to_string_lossy()); | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.