Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --print-path flag to print common paths #4307

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Args {
pub display_version: bool,
pub health: bool,
pub health_arg: Option<String>,
pub print_path: Option<String>,
pub load_tutor: bool,
pub fetch_grammars: bool,
pub build_grammars: bool,
Expand Down Expand Up @@ -44,6 +45,10 @@ impl Args {
args.health = true;
args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
}
"--print-path" => match argv.next().as_deref() {
Some(path) => args.print_path = Some(path.into()),
None => anyhow::bail!("--print-path must specify a kind"),
},
"-g" | "--grammar" => match argv.next().as_deref() {
Some("fetch") => args.fetch_grammars = true,
Some("build") => args.build_grammars = true,
Expand Down
17 changes: 16 additions & 1 deletion helix-term/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Context, Error, Result};
use anyhow::{anyhow, Context, Error, Result};
use crossterm::event::EventStream;
use helix_term::application::Application;
use helix_term::args::Args;
Expand Down Expand Up @@ -64,6 +64,8 @@ FLAGS:
--health [CATEGORY] Checks for potential errors in editor setup
CATEGORY can be a language or one of 'clipboard', 'languages'
or 'all'. 'all' is the default if not specified.
--print-path [KIND] Prints the path of a specific kind ('config-dir', 'config-file',
'runtime-dir', 'cache-dir', 'log-file', or 'lang-config-file').
-g, --grammar {{fetch|build}} Fetches or builds tree-sitter grammars listed in languages.toml
-c, --config <file> Specifies a file to use for configuration
-v Increases logging verbosity each use for up to 3 times
Expand Down Expand Up @@ -115,6 +117,19 @@ FLAGS:
return Ok(0);
}

if let Some(ref kind) = args.print_path {
match kind.as_str() {
"config-dir" => println!("{}", helix_loader::config_dir().display()),
"config-file" => println!("{}", helix_loader::config_file().display()),
"runtime-dir" => println!("{}", helix_loader::runtime_dir().display()),
"cache-dir" => println!("{}", helix_loader::cache_dir().display()),
"log-file" => println!("{}", helix_loader::log_file().display()),
"lang-config-file" => println!("{}", helix_loader::lang_config_file().display()),
_ => return Err(anyhow!("unknown path kind {}", kind)),
}
return Ok(0);
}

let logpath = args.log_file.as_ref().cloned().unwrap_or(logpath);
setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;

Expand Down