cli: remove the pkh context subcommand
The context management interface never worked reliably, and keeping it exposed presents a feature that is not ready. Contexts remain in the library as the execution backend for pkh deb (unshare chroots and friends); only the CLI surface goes.
This commit is contained in:
-102
@@ -3,7 +3,6 @@ use std::io::Write;
|
|||||||
|
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
use clap::{Command, arg, command};
|
use clap::{Command, arg, command};
|
||||||
use pkh::context::ContextConfig;
|
|
||||||
|
|
||||||
extern crate flate2;
|
extern crate flate2;
|
||||||
|
|
||||||
@@ -274,33 +273,6 @@ fn main() {
|
|||||||
.help("Print the pkh-native tag catalog and exit"),
|
.help("Print the pkh-native tag catalog and exit"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
|
||||||
Command::new("context")
|
|
||||||
.about("Manage contexts")
|
|
||||||
.subcommand_required(true)
|
|
||||||
.subcommand(
|
|
||||||
Command::new("create")
|
|
||||||
.about("Create a new context")
|
|
||||||
.arg(arg!(<name> "Context name"))
|
|
||||||
.arg(arg!(--type <type> "Context type: ssh (only type supported for now)"))
|
|
||||||
.arg(arg!(--endpoint <endpoint> "Context endpoint (for example: ssh://user@host:port)"))
|
|
||||||
)
|
|
||||||
.subcommand(
|
|
||||||
Command::new("rm")
|
|
||||||
.about("Remove a context")
|
|
||||||
.arg(arg!(<name> "Context name"))
|
|
||||||
)
|
|
||||||
.subcommand(
|
|
||||||
Command::new("ls")
|
|
||||||
.about("List contexts")
|
|
||||||
)
|
|
||||||
.subcommand(Command::new("show").about("Show current context"))
|
|
||||||
.subcommand(
|
|
||||||
Command::new("use")
|
|
||||||
.about("Set current context")
|
|
||||||
.arg(arg!(<name> "Context name"))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new("prune")
|
Command::new("prune")
|
||||||
.about("Prune residual pkh build artifacts and caches")
|
.about("Prune residual pkh build artifacts and caches")
|
||||||
@@ -716,80 +688,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(("context", sub_matches)) => {
|
|
||||||
let mgr = pkh::context::manager();
|
|
||||||
|
|
||||||
match sub_matches.subcommand() {
|
|
||||||
Some(("create", args)) => {
|
|
||||||
let name = args.get_one::<String>("name").unwrap();
|
|
||||||
let type_str = args
|
|
||||||
.get_one::<String>("type")
|
|
||||||
.map(|s| s.as_str())
|
|
||||||
.unwrap_or("local");
|
|
||||||
|
|
||||||
let context = match type_str {
|
|
||||||
"local" => ContextConfig::Local,
|
|
||||||
"ssh" => {
|
|
||||||
let endpoint =
|
|
||||||
args.get_one::<String>("endpoint").unwrap_or_else(|| {
|
|
||||||
error!(
|
|
||||||
"An --endpoint is required to create an ssh context. \
|
|
||||||
Expected format: [ssh://][user@]host[:port]"
|
|
||||||
);
|
|
||||||
std::process::exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
match pkh::context::ContextConfig::from_endpoint(endpoint) {
|
|
||||||
Ok(config) => config,
|
|
||||||
Err(e) => {
|
|
||||||
error!("{e}");
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
error!("Unknown context type: {}", type_str);
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(e) = mgr.add_context(name, context) {
|
|
||||||
error!("Failed to create context: {}", e);
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
info!("Context '{}' created.", name);
|
|
||||||
}
|
|
||||||
Some(("rm", args)) => {
|
|
||||||
let name = args.get_one::<String>("name").unwrap();
|
|
||||||
if let Err(e) = mgr.remove_context(name) {
|
|
||||||
error!("Failed to remove context: {}", e);
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
info!("Context '{}' removed.", name);
|
|
||||||
}
|
|
||||||
Some(("ls", _)) => {
|
|
||||||
let contexts = mgr.list_contexts();
|
|
||||||
let current = mgr.current_name();
|
|
||||||
for ctx in contexts {
|
|
||||||
if ctx == current {
|
|
||||||
println!("* {}", ctx);
|
|
||||||
} else {
|
|
||||||
println!(" {}", ctx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(("show", _)) => {}
|
|
||||||
Some(("use", args)) => {
|
|
||||||
let name = args.get_one::<String>("name").unwrap();
|
|
||||||
if let Err(e) = mgr.set_current(name) {
|
|
||||||
error!("Failed to set context: {}", e);
|
|
||||||
std::process::exit(1);
|
|
||||||
}
|
|
||||||
info!("Switched to context '{}'.", name);
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(("prune", sub_matches)) => {
|
Some(("prune", sub_matches)) => {
|
||||||
let dry_run = sub_matches
|
let dry_run = sub_matches
|
||||||
.get_one::<bool>("dry_run")
|
.get_one::<bool>("dry_run")
|
||||||
|
|||||||
Reference in New Issue
Block a user