add --show-config-path argument
This commit is contained in:
@@ -11,4 +11,8 @@ pub struct Arguments {
|
|||||||
/// the input files to edit
|
/// the input files to edit
|
||||||
#[arg(value_name = "files")]
|
#[arg(value_name = "files")]
|
||||||
pub files: Vec<PathBuf>,
|
pub files: Vec<PathBuf>,
|
||||||
|
|
||||||
|
/// print the path to the config file
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub show_config_path: bool,
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -34,7 +34,7 @@ pub struct Keypress {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn path() -> Option<PathBuf> {
|
fn default_path() -> Option<PathBuf> {
|
||||||
env::var_os("XDG_CONFIG_HOME")
|
env::var_os("XDG_CONFIG_HOME")
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
.take_if(|xdg_config_home| xdg_config_home.is_absolute())
|
.take_if(|xdg_config_home| xdg_config_home.is_absolute())
|
||||||
@@ -43,14 +43,17 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn path() -> Option<PathBuf> {
|
fn default_path() -> Option<PathBuf> {
|
||||||
// this isn't technically the right way but it should be good enough
|
// this isn't technically the right way but it should be good enough
|
||||||
home_dir().map(|home| home.join("AppData").join("Roaming"))
|
home_dir().map(|home| home.join("AppData").join("Roaming"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn path(override_path: Option<PathBuf>) -> Option<PathBuf> {
|
||||||
|
override_path.or_else(Self::default_path)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn init(override_path: Option<PathBuf>) -> Result<Self, ConfigInitError> {
|
pub fn init(override_path: Option<PathBuf>) -> Result<Self, ConfigInitError> {
|
||||||
let path = override_path
|
let path = Self::path(override_path)
|
||||||
.or_else(Self::path)
|
|
||||||
.ok_or(ConfigInitError::NoConfigPath)?;
|
.ok_or(ConfigInitError::NoConfigPath)?;
|
||||||
|
|
||||||
let raw_config = read_to_string(path)?;
|
let raw_config = read_to_string(path)?;
|
||||||
|
|||||||
+17
-1
@@ -11,6 +11,8 @@ use clap::Parser;
|
|||||||
use app::App;
|
use app::App;
|
||||||
use crossterm::{QueueableCommand, event::{DisableMouseCapture, EnableMouseCapture}};
|
use crossterm::{QueueableCommand, event::{DisableMouseCapture, EnableMouseCapture}};
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod buffer;
|
mod buffer;
|
||||||
mod popup;
|
mod popup;
|
||||||
@@ -33,12 +35,12 @@ const LINES_OF_PADDING: usize = 5;
|
|||||||
const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE;
|
const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE;
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// - update showcase
|
|
||||||
// - write docs
|
// - write docs
|
||||||
// - simonomi.dev/hexapoda?
|
// - simonomi.dev/hexapoda?
|
||||||
// - config
|
// - config
|
||||||
// - schema!!
|
// - schema!!
|
||||||
// - uhhhhh?
|
// - uhhhhh?
|
||||||
|
// - update showcase
|
||||||
// - fix scroll clamping
|
// - fix scroll clamping
|
||||||
// - inspector translations for varint
|
// - inspector translations for varint
|
||||||
// - search
|
// - search
|
||||||
@@ -71,6 +73,20 @@ const BYTES_OF_PADDING: usize = LINES_OF_PADDING * BYTES_PER_LINE;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let arguments = Arguments::parse();
|
let arguments = Arguments::parse();
|
||||||
|
|
||||||
|
if arguments.show_config_path {
|
||||||
|
if let Some(path) = Config::path(arguments.config) {
|
||||||
|
println!("{}", path.display());
|
||||||
|
} else {
|
||||||
|
#[cfg(unix)] {
|
||||||
|
println!("currently, no config file will be used. define the environment variable XDG_CONFIG_HOME or use the -c/--config option to provide one");
|
||||||
|
}
|
||||||
|
#[cfg(windows)] {
|
||||||
|
println!("currently, no config file will be used. use the -c/--config option to provide one");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let mut app = App::new(
|
let mut app = App::new(
|
||||||
arguments.config,
|
arguments.config,
|
||||||
&arguments.files
|
&arguments.files
|
||||||
|
|||||||
Reference in New Issue
Block a user