Support specifying read-only mode via CLI argument

Closes: https://github.com/sayanarijit/xplr/issues/22
pull/239/head
Arijit Basu 3 years ago committed by Arijit Basu
parent f12e1e5290
commit 844480204c

@ -11,6 +11,7 @@ use xplr::app;
struct Cli {
version: bool,
help: bool,
read_only: bool,
path: Option<PathBuf>,
config: Option<PathBuf>,
on_load: Vec<app::ExternalMsg>,
@ -50,6 +51,8 @@ impl Cli {
// Options
"-c" | "--config" => cli.config = args.pop_front().map(PathBuf::from),
"--read-only" => cli.read_only = true,
"--on-load" => {
while let Some(msg) = args.pop_front() {
if msg.starts_with('-') {
@ -84,10 +87,11 @@ fn main() {
xplr [FLAG]... [OPTION]... [PATH]"###;
let flags = r###"
- Read path from stdin
-- End of flags and options
-h, --help Prints help information
-V, --version Prints version information"###;
- Reads path from stdin
-- Denotes the end of command-line flags and options
--read-only Enables read-only mode (config.general.read_only)
-h, --help Prints help information
-V, --version Prints version information"###;
let options = r###"
-c, --config <PATH> Specifies a custom config file (default is
@ -115,7 +119,8 @@ fn main() {
} else {
match app::runner(cli.path.clone())
.map(|a| a.with_on_load(cli.on_load.clone()))
.map(|a| a.with_config(cli.config))
.map(|a| a.with_config(cli.config.clone()))
.map(|a| a.with_read_only(cli.read_only))
.and_then(|a| a.run())
{
Ok(Some(out)) => print!("{}", out),

@ -565,6 +565,11 @@ impl GeneralConfig {
pub fn disable_recover_mode(&self) -> bool {
self.disable_recover_mode
}
/// Set the general config's read only.
pub fn set_read_only(&mut self, read_only: bool) {
self.read_only = read_only;
}
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]

@ -92,6 +92,7 @@ pub struct Runner {
focused_path: Option<PathBuf>,
config: Option<PathBuf>,
on_load: Vec<app::ExternalMsg>,
read_only: bool,
}
impl Runner {
@ -109,6 +110,7 @@ impl Runner {
focused_path,
config: None,
on_load: Default::default(),
read_only: Default::default(),
})
}
@ -122,9 +124,15 @@ impl Runner {
self
}
pub fn with_read_only(mut self, read_only: bool) -> Self {
self.read_only = read_only;
self
}
pub fn run(self) -> Result<Option<String>> {
let lua = mlua::Lua::new();
let mut app = app::App::create(self.pwd, &lua, self.config)?;
app.config.general.set_read_only(self.read_only);
fs::create_dir_all(app.session_path())?;

Loading…
Cancel
Save