Skip to content

Commit c6873f0

Browse files
authoredJul 11, 2022
feat(cfg): support editor-args in config (#78)
* feat(cfg): supports editor-args in config * chore(cmd): fix typo Co-authored-by: clearloop <[email protected]>
1 parent 5566870 commit c6873f0

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
 

Diff for: ‎Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ path = "src/bin/lc.rs"
44

55
[package]
66
name = "leetcode-cli"
7-
version = "0.3.11"
7+
version = "0.3.12"
88
authors = ["clearloop <cdr.today@foxmail.com>"]
99
edition = "2021"
1010
description = "Leet your code in command-line."

Diff for: ‎src/cfg.rs

+2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ pub struct Urls {
132132
#[derive(Clone, Debug, Deserialize, Serialize)]
133133
pub struct Code {
134134
pub editor: String,
135+
#[serde(rename(serialize = "editor-args", deserialize = "editor-args"))]
136+
pub editor_args: Option<Vec<String>>,
135137
pub lang: String,
136138
pub pick: String,
137139
pub submission: String,

Diff for: ‎src/cmds/edit.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,27 @@ impl Command for EditCommand {
121121
}
122122
}
123123

124+
// Get arguments of the editor
125+
//
126+
// for example:
127+
//
128+
// ```toml
129+
// [code]
130+
// editor = "emacsclient"
131+
// editor-args = [ "-n", "-s", "doom" ]
132+
// ```
133+
//
134+
// ```rust
135+
// Command::new("emacsclient").args(&[ "-n", "-s", "doom", "<problem>" ])
136+
// ```
137+
let mut args: Vec<String> = Default::default();
138+
if let Some(editor_args) = conf.code.editor_args {
139+
args.extend_from_slice(&editor_args);
140+
}
141+
142+
args.push(path);
124143
std::process::Command::new(conf.code.editor)
125-
.arg(path)
144+
.args(args)
126145
.status()?;
127146
Ok(())
128147
}

0 commit comments

Comments
 (0)
Please sign in to comment.