feat(cli): merge --layout and --layout-path (#1426)
* Merge --layout and --layout-path * Fix e2e tests * style(comment): reword help text Co-authored-by: Aram Drevekenin <aram@poor.dev>
This commit is contained in:
parent
fd79b22d59
commit
2f58835f07
4 changed files with 16 additions and 14 deletions
|
|
@ -127,7 +127,7 @@ fn start_zellij_with_layout(channel: &mut ssh2::Channel, layout_path: &str) {
|
||||||
channel
|
channel
|
||||||
.write_all(
|
.write_all(
|
||||||
format!(
|
format!(
|
||||||
"{} --layout-path {} --session {} --data-dir {}\n",
|
"{} --layout {} --session {} --data-dir {}\n",
|
||||||
ZELLIJ_EXECUTABLE_LOCATION, layout_path, SESSION_NAME, ZELLIJ_DATA_DIR
|
ZELLIJ_EXECUTABLE_LOCATION, layout_path, SESSION_NAME, ZELLIJ_DATA_DIR
|
||||||
)
|
)
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,10 @@ pub struct CliArgs {
|
||||||
#[clap(long, short, overrides_with = "session")]
|
#[clap(long, short, overrides_with = "session")]
|
||||||
pub session: Option<String>,
|
pub session: Option<String>,
|
||||||
|
|
||||||
/// Name of a layout file in the layout directory
|
/// Name of a predefined layout or path to a layout file
|
||||||
#[clap(short, long, parse(from_os_str), overrides_with = "layout")]
|
#[clap(short, long, parse(from_os_str), overrides_with = "layout")]
|
||||||
pub layout: Option<PathBuf>,
|
pub layout: Option<PathBuf>,
|
||||||
|
|
||||||
/// Path to a layout yaml file
|
|
||||||
#[clap(long, parse(from_os_str), overrides_with = "layout_path")]
|
|
||||||
pub layout_path: Option<PathBuf>,
|
|
||||||
|
|
||||||
/// Change where zellij looks for the configuration file
|
/// Change where zellij looks for the configuration file
|
||||||
#[clap(short, long, overrides_with = "config", env = ZELLIJ_CONFIG_FILE_ENV, parse(from_os_str))]
|
#[clap(short, long, overrides_with = "config", env = ZELLIJ_CONFIG_FILE_ENV, parse(from_os_str))]
|
||||||
pub config: Option<PathBuf>,
|
pub config: Option<PathBuf>,
|
||||||
|
|
|
||||||
|
|
@ -239,12 +239,21 @@ impl LayoutFromYamlIntermediate {
|
||||||
|
|
||||||
pub fn from_path_or_default(
|
pub fn from_path_or_default(
|
||||||
layout: Option<&PathBuf>,
|
layout: Option<&PathBuf>,
|
||||||
layout_path: Option<&PathBuf>,
|
|
||||||
layout_dir: Option<PathBuf>,
|
layout_dir: Option<PathBuf>,
|
||||||
) -> Option<LayoutFromYamlIntermediateResult> {
|
) -> Option<LayoutFromYamlIntermediateResult> {
|
||||||
layout
|
layout
|
||||||
.map(|p| LayoutFromYamlIntermediate::from_dir(p, layout_dir.as_ref()))
|
.map(|layout| {
|
||||||
.or_else(|| layout_path.map(|p| LayoutFromYamlIntermediate::from_path(p)))
|
// The way we determine where to look for the layout is similar to
|
||||||
|
// how a path would look for an executable.
|
||||||
|
// See the gh issue for more: https://github.com/zellij-org/zellij/issues/1412#issuecomment-1131559720
|
||||||
|
if layout.extension().is_some() || layout.components().count() > 1 {
|
||||||
|
// We look localy!
|
||||||
|
LayoutFromYamlIntermediate::from_path(layout)
|
||||||
|
} else {
|
||||||
|
// We look in the default dir
|
||||||
|
LayoutFromYamlIntermediate::from_dir(layout, layout_dir.as_ref())
|
||||||
|
}
|
||||||
|
})
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
Some(LayoutFromYamlIntermediate::from_dir(
|
Some(LayoutFromYamlIntermediate::from_dir(
|
||||||
&std::path::PathBuf::from("default"),
|
&std::path::PathBuf::from("default"),
|
||||||
|
|
|
||||||
|
|
@ -223,11 +223,8 @@ impl Setup {
|
||||||
.layout_dir
|
.layout_dir
|
||||||
.clone()
|
.clone()
|
||||||
.or_else(|| get_layout_dir(opts.config_dir.clone().or_else(find_default_config_dir)));
|
.or_else(|| get_layout_dir(opts.config_dir.clone().or_else(find_default_config_dir)));
|
||||||
let layout_result = LayoutFromYamlIntermediate::from_path_or_default(
|
let layout_result =
|
||||||
opts.layout.as_ref(),
|
LayoutFromYamlIntermediate::from_path_or_default(opts.layout.as_ref(), layout_dir);
|
||||||
opts.layout_path.as_ref(),
|
|
||||||
layout_dir,
|
|
||||||
);
|
|
||||||
let layout = match layout_result {
|
let layout = match layout_result {
|
||||||
None => None,
|
None => None,
|
||||||
Some(Ok(layout)) => Some(layout),
|
Some(Ok(layout)) => Some(layout),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue