fix(cli): new-tab now also looks in layout_dir for layouts (#2198)

* fix(cli): the new-tab action now also searches for layouts in the layout dir

* style(fmt): rustfmt

* fix(tests): add missing parameter to cli action
This commit is contained in:
Aram Drevekenin 2023-02-26 22:11:08 +01:00 committed by GitHub
parent a1f5635176
commit 52de5b7db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 4 deletions

View File

@ -2370,6 +2370,7 @@ pub fn send_cli_new_tab_action_default_params() {
let new_tab_action = CliAction::NewTab {
name: None,
layout: None,
layout_dir: None,
cwd: None,
};
send_cli_action_to_server(
@ -2414,6 +2415,7 @@ pub fn send_cli_new_tab_action_with_name_and_layout() {
"{}/src/unit/fixtures/layout-with-three-panes.kdl",
env!("CARGO_MANIFEST_DIR")
))),
layout_dir: None,
cwd: None,
};
send_cli_action_to_server(

View File

@ -352,6 +352,10 @@ pub enum CliAction {
#[clap(short, long, value_parser)]
layout: Option<PathBuf>,
/// Default folder to look for layouts
#[clap(short, long, value_parser, requires("layout"))]
layout_dir: Option<PathBuf>,
/// Name of the new tab
#[clap(short, long, value_parser)]
name: Option<String>,

View File

@ -9,6 +9,7 @@ use crate::data::InputMode;
use crate::data::{Direction, Resize};
use crate::input::config::{ConfigError, KdlError};
use crate::input::options::OnForceClose;
use crate::setup::{find_default_config_dir, get_layout_dir};
use miette::{NamedSource, Report};
use serde::{Deserialize, Serialize};
@ -348,14 +349,21 @@ impl Action {
Action::TabNameInput(name.as_bytes().to_vec()),
]),
CliAction::UndoRenameTab => Ok(vec![Action::UndoRenameTab]),
CliAction::NewTab { name, layout, cwd } => {
CliAction::NewTab {
name,
layout,
layout_dir,
cwd,
} => {
let current_dir = get_current_dir();
let cwd = cwd
.map(|cwd| current_dir.join(cwd))
.or_else(|| Some(current_dir));
if let Some(layout_path) = layout {
let layout_dir =
layout_dir.or_else(|| get_layout_dir(find_default_config_dir()));
let (path_to_raw_layout, raw_layout, swap_layouts) =
Layout::stringified_from_path_or_default(Some(&layout_path), None)
Layout::stringified_from_path_or_default(Some(&layout_path), layout_dir)
.map_err(|e| format!("Failed to load layout: {}", e))?;
let layout = Layout::from_str(&raw_layout, path_to_raw_layout, swap_layouts.as_ref().map(|(f, p)| (f.as_str(), p.as_str())), cwd).map_err(|e| {
let stringified_error = match e {

View File

@ -291,8 +291,8 @@ impl Setup {
/// file options, superceeding the config file options:
/// 1. command line options (`zellij options`)
/// 2. layout options
/// (`layout.yaml` / `zellij --layout`)
/// 3. config options (`config.yaml`)
/// (`layout.kdl` / `zellij --layout`)
/// 3. config options (`config.kdl`)
pub fn from_cli_args(cli_args: &CliArgs) -> Result<(Config, Layout, Options), ConfigError> {
// note that this can potentially exit the process
Setup::handle_setup_commands(cli_args);