@@ -1,16 +1,9 @@
1−#![allow(unused)]
2−
3−mod application;
4−mod commands;
5−mod compositor;
6−mod keymap;
7−mod ui;
8−
9−use application::Application;
1+use helix_term::application::Application;
2+use helix_term::args::Args;
103
114use std::path::PathBuf;
125
13−use anyhow::{Context, Error, Result};
6+use anyhow::{Context, Result};
147
158fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
169 let mut base_config = fern::Dispatch::new();
@@ -45,58 +38,11 @@ fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
4538 Ok(())
4639}
4740
48−pub struct Args {
49− display_help: bool,
50− display_version: bool,
51− verbosity: u64,
52− files: Vec<PathBuf>,
53−}
54−
55−fn parse_args(mut args: Args) -> Result<Args> {
56− let argv: Vec<String> = std::env::args().collect();
57− let mut iter = argv.iter();
58−
59− iter.next(); // skip the program, we don't care about that
60−
61− while let Some(arg) = iter.next() {
62− match arg.as_str() {
63− "--" => break, // stop parsing at this point treat the remaining as files
64− "--version" => args.display_version = true,
65− "--help" => args.display_help = true,
66− arg if arg.starts_with("--") => {
67− return Err(Error::msg(format!(
68− "unexpected double dash argument: {}",
69− arg
70− )))
71− }
72− arg if arg.starts_with('-') => {
73− let arg = arg.get(1..).unwrap().chars();
74− for chr in arg {
75− match chr {
76− 'v' => args.verbosity += 1,
77− 'V' => args.display_version = true,
78− 'h' => args.display_help = true,
79− _ => return Err(Error::msg(format!("unexpected short arg {}", chr))),
80− }
81− }
82− }
83− arg => args.files.push(PathBuf::from(arg)),
84− }
85− }
86−
87− // push the remaining args, if any to the files
88− for filename in iter {
89− args.files.push(PathBuf::from(filename));
90− }
91−
92− Ok(args)
93−}
94−
9541#[tokio::main]
9642async fn main() -> Result<()> {
9743 let cache_dir = helix_core::cache_dir();
9844 if !cache_dir.exists() {
99− std::fs::create_dir(&cache_dir);
45+ std::fs::create_dir(&cache_dir).ok();
10046 }
10147
10248 let logpath = cache_dir.join("helix.log");
@@ -125,14 +71,7 @@ FLAGS:
12571 logpath.display(),
12672 );
12773
128− let mut args: Args = Args {
129− display_help: false,
130− display_version: false,
131− verbosity: 0,
132− files: [].to_vec(),
133− };
134−
135− args = parse_args(args).context("could not parse arguments")?;
74+ let args = Args::parse_args().context("could not parse arguments")?;
13675
13776 // Help has a higher priority and should be handled separately.
13877 if args.display_help {
@@ -147,14 +86,14 @@ FLAGS:
14786
14887 let conf_dir = helix_core::config_dir();
14988 if !conf_dir.exists() {
150− std::fs::create_dir(&conf_dir);
89+ std::fs::create_dir(&conf_dir).ok();
15190 }
15291
15392 setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
15493
15594 // TODO: use the thread local executor to spawn the application task separately from the work pool
15695 let mut app = Application::new(args).context("unable to create new appliction")?;
157− app.run().await;
96+ app.run().await.unwrap();
15897
15998 Ok(())
16099}