@@ -1,16 +1,9 @@
9−use application::Application;
1+use helix_term::application::Application;
2+use helix_term::args::Args;
11use std::path::PathBuf;
4use std::path::PathBuf;
13−use anyhow::{Context, Error, Result};
6+use anyhow::{Context, Result};
15fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
8fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
16 let mut base_config = fern::Dispatch::new();
9 let mut base_config = fern::Dispatch::new();
@@ -45,58 +38,11 @@ fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
50− display_version: bool,
55−fn parse_args(mut args: Args) -> Result<Args> {
56− let argv: Vec<String> = std::env::args().collect();
57− let mut iter = argv.iter();
59− iter.next(); // skip the program, we don't care about that
61− while let Some(arg) = iter.next() {
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: {}",
72− arg if arg.starts_with('-') => {
73− let arg = arg.get(1..).unwrap().chars();
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))),
83− arg => args.files.push(PathBuf::from(arg)),
87− // push the remaining args, if any to the files
88− for filename in iter {
89− args.files.push(PathBuf::from(filename));
95#[tokio::main]
41#[tokio::main]
96async fn main() -> Result<()> {
42async fn main() -> Result<()> {
97 let cache_dir = helix_core::cache_dir();
43 let cache_dir = helix_core::cache_dir();
98 if !cache_dir.exists() {
44 if !cache_dir.exists() {
99− std::fs::create_dir(&cache_dir);
45+ std::fs::create_dir(&cache_dir).ok();
102 let logpath = cache_dir.join("helix.log");
48 let logpath = cache_dir.join("helix.log");
@@ -125,14 +71,7 @@ FLAGS:
125 logpath.display(),
71 logpath.display(),
128− let mut args: Args = Args {
129− display_help: false,
130− display_version: false,
135− args = parse_args(args).context("could not parse arguments")?;
74+ let args = Args::parse_args().context("could not parse arguments")?;
137 // Help has a higher priority and should be handled separately.
76 // Help has a higher priority and should be handled separately.
138 if args.display_help {
77 if args.display_help {
@@ -147,14 +86,14 @@ FLAGS:
148 let conf_dir = helix_core::config_dir();
87 let conf_dir = helix_core::config_dir();
149 if !conf_dir.exists() {
88 if !conf_dir.exists() {
150− std::fs::create_dir(&conf_dir);
89+ std::fs::create_dir(&conf_dir).ok();
153 setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
92 setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
155 // TODO: use the thread local executor to spawn the application task separately from the work pool
94 // TODO: use the thread local executor to spawn the application task separately from the work pool
156 let mut app = Application::new(args).context("unable to create new appliction")?;
95 let mut app = Application::new(args).context("unable to create new appliction")?;
157− app.run().await;
96+ app.run().await.unwrap();