Skip to content

Commit

Permalink
add --config
Browse files Browse the repository at this point in the history
  • Loading branch information
hatoo committed Feb 24, 2020
1 parent 871eb4f commit 3f1b802
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ aho-corasick = "0.7"
iter-read = "0.2"
rbtag = "0.3"
failure = "0.1"
anyhow = "1"
toml = "0.5"
ansi_colours = "1"
typemap = "0.3"
Expand Down
19 changes: 16 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct Snippet {
body: Vec<String>,
}

fn main() {
fn main() -> anyhow::Result<()> {
let config_path = dirs::config_dir().map(|mut p| {
p.push("acc");
p.push("config.toml");
Expand All @@ -50,11 +50,13 @@ fn main() {
.about("A text editor to be ACCEPTED")
.after_help(after_help.as_str())
.bin_name("acc")
.arg(Arg::with_name("config").long("config"))
.arg(Arg::with_name("file").multiple(true))
.get_matches();

let config = config_path
.and_then(|config_path| fs::read_to_string(&config_path).ok())
.as_ref()
.and_then(|config_path| fs::read_to_string(config_path).ok())
.and_then(|s| {
let result = config::parse_config_with_default(s.as_str());
match result {
Expand Down Expand Up @@ -91,6 +93,17 @@ fn main() {
let mut state: BufferTab<accepted::core::buffer::RopeyCoreBuffer> =
BufferTab::new(&syntax_parent, &config);

if matches.is_present("config") {
if let Some(config_path) = config_path.as_ref() {
if let Some(parent) = config_path.parent() {
std::fs::create_dir_all(parent)?;
}
state.open(config_path.clone());
} else {
anyhow::bail!("No config path detected in this system");
}
}

let files = matches.values_of_os("file");
if let Some(files) = files {
for path in files {
Expand Down Expand Up @@ -118,7 +131,7 @@ fn main() {
draw.redraw();
}
if state.event(evt) {
return;
return Ok(());
}
}

Expand Down

0 comments on commit 3f1b802

Please sign in to comment.