Merge pull request #623 from a-kenji/feature/dump-layout

Add cmd to dump `layout` to stdout
This commit is contained in:
a-kenji 2021-07-22 18:44:29 +02:00 committed by GitHub
commit e2d086d591
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 3 deletions

View file

@ -36,8 +36,14 @@ pub fn main() {
let config_options = Options::from_cli(&config.options, opts.command.clone()); let config_options = Options::from_cli(&config.options, opts.command.clone());
if let Some(Command::Setup(ref setup)) = opts.command { if let Some(Command::Setup(ref setup)) = opts.command {
Setup::from_cli(setup, &opts, &config_options).expect("Failed to print to stdout"); Setup::from_cli(setup, &opts, &config_options).map_or_else(
} |e| {
eprintln!("{:?}", e);
process::exit(1);
},
|_| {},
);
};
atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap(); atomic_create_dir(&*ZELLIJ_TMP_DIR).unwrap();
atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap(); atomic_create_dir(&*ZELLIJ_TMP_LOG_DIR).unwrap();

View file

@ -96,13 +96,25 @@ pub const STRIDER_LAYOUT: &[u8] = include_bytes!(concat!(
pub const NO_STATUS_LAYOUT: &[u8] = include_bytes!(concat!( pub const NO_STATUS_LAYOUT: &[u8] = include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"), env!("CARGO_MANIFEST_DIR"),
"/", "/",
"assets/layouts/default.yaml" "assets/layouts/disable-status-bar.yaml"
)); ));
pub fn dump_default_config() -> std::io::Result<()> { pub fn dump_default_config() -> std::io::Result<()> {
dump_asset(DEFAULT_CONFIG) dump_asset(DEFAULT_CONFIG)
} }
pub fn dump_specified_layout(layout: &str) -> std::io::Result<()> {
match layout {
"strider" => dump_asset(STRIDER_LAYOUT),
"default" => dump_asset(DEFAULT_LAYOUT),
"disable-status" => dump_asset(NO_STATUS_LAYOUT),
not_found => Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("Layout: {} not found", not_found),
)),
}
}
#[derive(Debug, Default, Clone, StructOpt, Serialize, Deserialize)] #[derive(Debug, Default, Clone, StructOpt, Serialize, Deserialize)]
pub struct Setup { pub struct Setup {
/// Dump the default configuration file to stdout /// Dump the default configuration file to stdout
@ -117,6 +129,9 @@ pub struct Setup {
#[structopt(long)] #[structopt(long)]
pub check: bool, pub check: bool,
/// Dump the specified layout file to stdout
#[structopt(long)]
pub dump_layout: Option<String>,
/// Generates completion for the specified shell /// Generates completion for the specified shell
#[structopt(long)] #[structopt(long)]
pub generate_completion: Option<String>, pub generate_completion: Option<String>,
@ -144,6 +159,11 @@ impl Setup {
std::process::exit(0); std::process::exit(0);
} }
if let Some(layout) = &self.dump_layout {
dump_specified_layout(layout)?;
std::process::exit(0);
}
Ok(()) Ok(())
} }