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

add remove command for CLI #2923

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ pub enum Command {
#[clap(long, action)]
force: bool,
},
/// Remove a existed program.
Remove {
/// Program name
name: String,
},
/// Commands for interacting with interface definitions.
Idl {
#[clap(subcommand)]
Expand Down Expand Up @@ -681,6 +686,7 @@ fn process_command(opts: Opts) -> Result<()> {
template,
force,
} => new(&opts.cfg_override, solidity, name, template, force),
Command::Remove { name } => remove(&opts.cfg_override, name),
Command::Build {
no_idl,
idl,
Expand Down Expand Up @@ -1044,6 +1050,41 @@ fn new(
})
}

// Remove the program crate in the `programs/<name>` directory.
pub fn remove(cfg_override: &ConfigOverride, name: String) -> Result<()> {
with_workspace(cfg_override, |cfg| {
match cfg.path().parent() {
None => {
println!("Unable to make new program");
}
Some(parent) => {
std::env::set_current_dir(parent)?;

let cluster = cfg.provider.cluster.clone();
let programs = cfg.programs.entry(cluster).or_default();
if programs.contains_key(&name) {
// Delete all files within the program folder
fs::remove_dir_all(
std::env::current_dir()?
.join("programs")
.join(&name),
)?;
}

print!("There");

programs.remove(&name);

let toml = cfg.to_string();
fs::write("Anchor.toml", toml)?;

println!("Removed program.");
}
};
Ok(())
})
}

/// Array of (path, content) tuple.
pub type Files = Vec<(PathBuf, String)>;

Expand Down