Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: take ownership of command arguments #3539

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/subcommands/attach_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ impl AttachCommand {
Ok(())
}

pub fn run(&self, config: Config) -> anyhow::Result<()> {
pub fn run(self, config: Config) -> anyhow::Result<()> {
let mut context = Context::default();
self.setup_context(&mut context, &config.client.rpc_token);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/auth_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn process_perms(perm: String) -> Result<Vec<String>, JsonRpcError> {
}

impl AuthCommands {
pub async fn run(&self, config: Config) -> anyhow::Result<()> {
pub async fn run(self, config: Config) -> anyhow::Result<()> {
match self {
Self::CreateToken { perm } => {
let perm: String = perm.parse()?;
Expand Down
18 changes: 9 additions & 9 deletions src/cli/subcommands/chain_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,29 @@ pub enum ChainCommands {
}

impl ChainCommands {
pub async fn run(&self, config: Config) -> anyhow::Result<()> {
pub async fn run(self, config: Config) -> anyhow::Result<()> {
match self {
Self::Block { cid } => print_rpc_res_pretty(
chain_get_block(((*cid).into(),), &config.client.rpc_token).await,
),
Self::Block { cid } => {
print_rpc_res_pretty(chain_get_block((cid.into(),), &config.client.rpc_token).await)
}
Self::Genesis => {
print_rpc_res_pretty(chain_get_genesis(&config.client.rpc_token).await)
}
Self::Head => print_rpc_res_cids(chain_head(&config.client.rpc_token).await),
Self::Message { cid } => print_rpc_res_pretty(
chain_get_message(((*cid).into(),), &config.client.rpc_token).await,
chain_get_message((cid.into(),), &config.client.rpc_token).await,
),
Self::ReadObj { cid } => {
print_rpc_res(chain_read_obj(((*cid).into(),), &config.client.rpc_token).await)
print_rpc_res(chain_read_obj((cid.into(),), &config.client.rpc_token).await)
}
Self::SetHead {
cids,
epoch: Some(epoch),
force: no_confirm,
} => {
maybe_confirm(*no_confirm, SET_HEAD_CONFIRMATION_MESSAGE)?;
maybe_confirm(no_confirm, SET_HEAD_CONFIRMATION_MESSAGE)?;
assert!(cids.is_empty(), "should be disallowed by clap");
tipset_by_epoch_or_offset(*epoch, &config.client.rpc_token)
tipset_by_epoch_or_offset(epoch, &config.client.rpc_token)
.and_then(|tipset_json| {
chain_set_head(
(tipset_json.into_inner().key().clone(),),
Expand All @@ -93,7 +93,7 @@ impl ChainCommands {
epoch: None,
force: no_confirm,
} => {
maybe_confirm(*no_confirm, SET_HEAD_CONFIRMATION_MESSAGE)?;
maybe_confirm(no_confirm, SET_HEAD_CONFIRMATION_MESSAGE)?;
chain_set_head(
(TipsetKeys::from_iter(cids.clone()),),
&config.client.rpc_token,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/config_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub enum ConfigCommands {
}

impl ConfigCommands {
pub fn run<W: Write + Unpin>(&self, config: &Config, sink: &mut W) -> anyhow::Result<()> {
pub fn run<W: Write + Unpin>(self, config: &Config, sink: &mut W) -> anyhow::Result<()> {
match self {
Self::Dump => writeln!(
sink,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/db_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum DBCommands {
}

impl DBCommands {
pub async fn run(&self, config: &Config) -> anyhow::Result<()> {
pub async fn run(self, config: &Config) -> anyhow::Result<()> {
match self {
Self::Stats => bail_moved_cmd("db stats", "forest-tool db stats"),
Self::GC => {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl NodeStatusInfo {
}

impl InfoCommand {
pub async fn run(&self, config: Config, _opts: &CliOpts) -> anyhow::Result<()> {
pub async fn run(self, config: Config, _opts: &CliOpts) -> anyhow::Result<()> {
let res = tokio::try_join!(
node_status((), &config.client.rpc_token),
chain_head(&config.client.rpc_token),
Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/net_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum NetCommands {
}

impl NetCommands {
pub async fn run(&self, config: Config) -> anyhow::Result<()> {
pub async fn run(self, config: Config) -> anyhow::Result<()> {
match self {
Self::Listen => {
let info = net_addrs_listen((), &config.client.rpc_token)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/send_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct SendCommand {
}

impl SendCommand {
pub async fn run(&self, config: Config) -> anyhow::Result<()> {
pub async fn run(self, config: Config) -> anyhow::Result<()> {
let from: Address = if let Some(from) = &self.from {
StrictAddress::from_str(from)?.into()
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/shutdown_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ShutdownCommand {
}

impl ShutdownCommand {
pub async fn run(&self, config: Config) -> anyhow::Result<()> {
pub async fn run(self, config: Config) -> anyhow::Result<()> {
println!("Shutting down Forest node");
if !self.force && !prompt_confirm() {
println!("Aborted.");
Expand Down
4 changes: 1 addition & 3 deletions src/cli/subcommands/sync_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ pub enum SyncCommands {
}

impl SyncCommands {
pub async fn run(&self, config: Config) -> anyhow::Result<()> {
pub async fn run(self, config: Config) -> anyhow::Result<()> {
match self {
Self::Wait { watch } => {
let watch = *watch;

let ticker = Ticker::new(0.., Duration::from_secs(1));
let mut stdout = stdout();

Expand Down