Skip to content

Chain add command#51

Open
hannydevelop wants to merge 10 commits intoold-mainfrom
ukpai/add
Open

Chain add command#51
hannydevelop wants to merge 10 commits intoold-mainfrom
ukpai/add

Conversation

@hannydevelop
Copy link
Copy Markdown
Contributor

@hannydevelop hannydevelop commented May 19, 2022

closes #32

@hannydevelop hannydevelop marked this pull request as draft May 23, 2022 13:59
@hannydevelop hannydevelop marked this pull request as ready for review May 25, 2022 15:02
.await
.map_err(|e| e.into())
.unwrap_or_else(|err| {
panic!("executor exited with error: {}", err);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return an error instead,

ChainRegistryError::Request() takes in an octocrab::Error

let status = response.status();

if status == 404 {
panic!("Chain not found in registry")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, ChainRegistryError::UnsupportedChain is made for this

let mut vec = Vec::new();
vec.push(chain_info);

if !chain_content.contains(chain_name) {
Copy link
Copy Markdown
Member

@cbrit cbrit Jun 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the chain exists in the config we can avoid a call to github by putting a check for this before the async block.

Comment on lines +51 to +54
let mut file = fs::OpenOptions::new()
.append(true)
.open(config_file)
.expect("Could not open file");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be a better UX if the list of chains is in alphabetical order like lens has it, which appending can't accomplish.

I'd forgotten but there is actually an OcularCliConfig struct for serializing/deserializing the config file already in config.rs that can replace the Chains struct in this file. You should be able to deserialize the file to it and edit the chains vec (and sort):

/// OcularCli Configuration
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct OcularCliConfig {
/// Chain related config, not read in from file
pub default_chain: String,
/// Locally cached chains
pub chains: Vec<ChainInfo>,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ocular_CLI (Add Chain)

2 participants