From d1ef8a1784c3587c191e2c08b5620d997b897616 Mon Sep 17 00:00:00 2001 From: anastasia Date: Fri, 26 Mar 2021 19:37:54 +0300 Subject: [PATCH] [issue #7] CLI parse args for pg subcommand --- Cargo.lock | 7 ++++++ src/bin/cli/pg.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c976cbb117..7c4f07b534 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "anyhow" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cddc5f91628367664cc7c69714ff08deee8a3efc54623011c772544d7b2767" + [[package]] name = "arc-swap" version = "1.2.0" @@ -1131,6 +1137,7 @@ dependencies = [ name = "pageserver" version = "0.1.0" dependencies = [ + "anyhow", "byteorder", "bytes", "chrono", diff --git a/src/bin/cli/pg.rs b/src/bin/cli/pg.rs index 534bcef426..a2444d1c0d 100644 --- a/src/bin/cli/pg.rs +++ b/src/bin/cli/pg.rs @@ -3,6 +3,8 @@ use anyhow::{Result}; use crate::subcommand; + + pub struct PgCmd<'a> { pub clap_cmd: clap::App<'a, 'a>, } @@ -14,22 +16,72 @@ impl subcommand::SubCommand for PgCmd<'_> { .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( App::new("list") + .about("List existing compute nodes") ) .subcommand( App::new("create") - .arg(Arg::with_name("pgdata").required(true)), + .about("Create (init) new data directory using given storage and start postgres") + .arg(Arg::with_name("name") + .short("n") + .long("name") + .takes_value(true) + .help("Name of the compute node")) + .arg(Arg::with_name("storage") + .short("s") + .long("storage") + .takes_value(true) + .help("Name of the storage node to use")) + //TODO should it be just name of uploaded snapshot or some path? + .arg(Arg::with_name("snapshot") + .long("snapshot") + .takes_value(true) + .help("Name of the snapshot to use")) + .arg(Arg::with_name("nostart") + .long("no-start") + .takes_value(false) + .help("Don't start postgres on the created node")) ) .subcommand( App::new("destroy") + .about("Stop postgres and destroy node's data directory") + .arg(Arg::with_name("name") + .short("n") + .long("name") + .takes_value(true) + .help("Name of the compute node")) ) .subcommand( App::new("start") + .about("Start postgres on the given node") + .arg(Arg::with_name("name") + .short("n") + .long("name") + .takes_value(true) + .help("Name of the compute node")) + .arg(Arg::with_name("replica") + .long("replica") + .takes_value(false) + .help("Start the compute node as replica")) ) .subcommand( App::new("stop") + .about("Stop postgres on the given node") + .arg(Arg::with_name("name") + .short("n") + .long("name") + .takes_value(true) + .help("Name of the compute node")) + ) .subcommand( App::new("show") + .about("Show info about the given node") + .arg(Arg::with_name("name") + .short("n") + .long("name") + .takes_value(true) + .help("Name of the compute node")) + ) }