Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Remove show flag from config command
Browse files Browse the repository at this point in the history
`$ pulsar config -s` has been replaced with `$ pulsar config` to show the already set config params/fields details.
  • Loading branch information
abhi3700 committed Feb 5, 2024
1 parent a82110f commit fd985c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
28 changes: 16 additions & 12 deletions pulsar/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//!
//! ### Show
//! ```bash
//! $ pulsar config -s
//! $ pulsar config
//! Current Config set as:
//! {
//! "chain": "Gemini3g",
Expand Down Expand Up @@ -77,7 +77,6 @@ use crate::utils::{create_or_move_data, reward_address_parser, size_parser};

// function for config cli command
pub(crate) async fn config(
show: bool,
chain: Option<String>,
farm_size: Option<String>,
reward_address: Option<String>,
Expand All @@ -95,16 +94,12 @@ pub(crate) async fn config(
// Load the current configuration
let mut config: Config = parse_config()?;

if show {
// Display the current configuration as JSON
// Serialize `config` to a pretty-printed JSON string
let serialized = serde_json::to_string_pretty(&config)?;
println!(
"Current Config set as: \n{}\nin file: {:?}",
serialized,
config_path.to_str().expect("Expected stringified config path")
);
} else {
if chain.is_some()
|| farm_size.is_some()
|| reward_address.is_some()
|| node_dir.is_some()
|| farm_dir.is_some()
{
// no options provided
if chain.is_none()
&& farm_size.is_none()
Expand Down Expand Up @@ -162,6 +157,15 @@ pub(crate) async fn config(

// Save the updated configuration back to the file
fs::write(config_path, toml::to_string(&config)?)?;
} else {
// Display the current configuration as JSON
// Serialize `config` to a pretty-printed JSON string
let serialized = serde_json::to_string_pretty(&config)?;
println!(
"Current Config already set as: \n{}\nin file: {:?}",
serialized,
config_path.to_str().expect("Expected stringified config path")
);
}

Ok(())
Expand Down
9 changes: 3 additions & 6 deletions pulsar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ enum Commands {
about = "set the config params: chain, farm-size, reward-address, node-dir, farm-dir"
)]
Config {
#[arg(short, long, action)]
show: bool,
#[arg(short, long, action)]
chain: Option<String>,
#[arg(short, long, action)]
Expand Down Expand Up @@ -106,8 +104,8 @@ async fn main() -> Result<(), Report> {
Some(Commands::Wipe { farmer, node }) => {
wipe_config(farmer, node).await.suggestion(support_message())?;
}
Some(Commands::Config { chain, show, farm_size, reward_address, node_dir, farm_dir }) => {
config(show, chain, farm_size, reward_address, node_dir, farm_dir)
Some(Commands::Config { chain, farm_size, reward_address, node_dir, farm_dir }) => {
config(chain, farm_size, reward_address, node_dir, farm_dir)
.await
.suggestion(support_message())?;
}
Expand Down Expand Up @@ -200,7 +198,7 @@ async fn arrow_key_mode() -> Result<(), Report> {
info().await.suggestion(support_message())?;
}
4 => {
config(true, None, None, None, None, None).await.suggestion(support_message())?;
config(None, None, None, None, None).await.suggestion(support_message())?;
}
5 => {
open_log_dir().suggestion(support_message())?;
Expand Down Expand Up @@ -249,7 +247,6 @@ impl std::fmt::Display for Commands {
Commands::Info => write!(f, "info"),
Commands::Init => write!(f, "init"),
Commands::Config {
show: _,
chain: _,
farm_size: _,
reward_address: _,
Expand Down

0 comments on commit fd985c5

Please sign in to comment.