Skip to content

Commit

Permalink
Add option to not read any config file
Browse files Browse the repository at this point in the history
  • Loading branch information
WGUNDERWOOD committed Dec 6, 2024
1 parent 66ec0f4 commit 9382eef
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ is available at

Note for contributors: this repository's configuration file will be
automatically applied if tex-fmt is run from within the repository.
Change working directory or use `--config <config>` to avoid this.
Use `--noconfig` or `--config <config>` to avoid this.

### Disabling the formatter

Expand Down Expand Up @@ -297,3 +297,4 @@ The following command-line options are offered by tex-fmt.
| `--completion` | | | Generate a shell completion script |
| `--man` | | | Generate a man page |
| `--args` | | | View arguments passed to tex-fmt |
| `--noconfig` | | | Do not read any config file |
1 change: 1 addition & 0 deletions completion/_tex-fmt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ _tex-fmt() {
'--usetabs[Use tabs instead of spaces for indentation]' \
'--man[Generate man page]' \
'--args[Print arguments passed to tex-fmt and exit]' \
'--noconfig[Do not read any config file]' \
'-h[Print help]' \
'--help[Print help]' \
'::files -- List of files to be formatted:_default' \
Expand Down
1 change: 1 addition & 0 deletions completion/_tex-fmt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Register-ArgumentCompleter -Native -CommandName 'tex-fmt' -ScriptBlock {
[CompletionResult]::new('--usetabs', '--usetabs', [CompletionResultType]::ParameterName, 'Use tabs instead of spaces for indentation')
[CompletionResult]::new('--man', '--man', [CompletionResultType]::ParameterName, 'Generate man page')
[CompletionResult]::new('--args', '--args', [CompletionResultType]::ParameterName, 'Print arguments passed to tex-fmt and exit')
[CompletionResult]::new('--noconfig', '--noconfig', [CompletionResultType]::ParameterName, 'Do not read any config file')
[CompletionResult]::new('-h', '-h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, 'Print help')
break
Expand Down
2 changes: 1 addition & 1 deletion completion/tex-fmt.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _tex-fmt() {

case "${cmd}" in
tex__fmt)
opts="-c -p -n -v -q -s -t -l -h --check --print --nowrap --verbose --quiet --trace --stdin --tabsize --usetabs --wraplen --config --completion --man --args --help [files]..."
opts="-c -p -n -v -q -s -t -l -h --check --print --nowrap --verbose --quiet --trace --stdin --tabsize --usetabs --wraplen --config --completion --man --args --noconfig --help [files]..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
1 change: 1 addition & 0 deletions completion/tex-fmt.elv
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set edit:completion:arg-completer[tex-fmt] = {|@words|
cand --usetabs 'Use tabs instead of spaces for indentation'
cand --man 'Generate man page'
cand --args 'Print arguments passed to tex-fmt and exit'
cand --noconfig 'Do not read any config file'
cand -h 'Print help'
cand --help 'Print help'
}
Expand Down
1 change: 1 addition & 0 deletions completion/tex-fmt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ complete -c tex-fmt -s s -l stdin -d 'Process stdin as a single file, output to
complete -c tex-fmt -l usetabs -d 'Use tabs instead of spaces for indentation'
complete -c tex-fmt -l man -d 'Generate man page'
complete -c tex-fmt -l args -d 'Print arguments passed to tex-fmt and exit'
complete -c tex-fmt -l noconfig -d 'Do not read any config file'
complete -c tex-fmt -s h -l help -d 'Print help'
5 changes: 4 additions & 1 deletion man/tex-fmt.1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.SH NAME
tex\-fmt \- An extremely fast LaTeX formatter written in Rust
.SH SYNOPSIS
\fBtex\-fmt\fR [\fB\-c\fR|\fB\-\-check\fR] [\fB\-p\fR|\fB\-\-print\fR] [\fB\-n\fR|\fB\-\-nowrap\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-trace\fR] [\fB\-s\fR|\fB\-\-stdin\fR] [\fB\-t\fR|\fB\-\-tabsize\fR] [\fB\-\-usetabs\fR] [\fB\-l\fR|\fB\-\-wraplen\fR] [\fB\-\-config\fR] [\fB\-\-completion\fR] [\fB\-\-man\fR] [\fB\-\-args\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIfiles\fR]
\fBtex\-fmt\fR [\fB\-c\fR|\fB\-\-check\fR] [\fB\-p\fR|\fB\-\-print\fR] [\fB\-n\fR|\fB\-\-nowrap\fR] [\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-q\fR|\fB\-\-quiet\fR] [\fB\-\-trace\fR] [\fB\-s\fR|\fB\-\-stdin\fR] [\fB\-t\fR|\fB\-\-tabsize\fR] [\fB\-\-usetabs\fR] [\fB\-l\fR|\fB\-\-wraplen\fR] [\fB\-\-config\fR] [\fB\-\-completion\fR] [\fB\-\-man\fR] [\fB\-\-args\fR] [\fB\-\-noconfig\fR] [\fB\-h\fR|\fB\-\-help\fR] [\fIfiles\fR]
.SH DESCRIPTION
An extremely fast LaTeX formatter written in Rust
.SH OPTIONS
Expand Down Expand Up @@ -55,6 +55,9 @@ Generate man page
\fB\-\-args\fR
Print arguments passed to tex\-fmt and exit
.TP
\fB\-\-noconfig\fR
Do not read any config file
.TP
\fB\-h\fR, \fB\-\-help\fR
Print help
.TP
Expand Down
2 changes: 1 addition & 1 deletion notes.org
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
** TODO Improve build times
** TODO Include man page and shell completion in Nix package
** TODO Add to Nix home-manager with empty config file
** TODO Add option for no config file
* Options and documentation
** Args struct
** OptionArgs struct
** CLI command
** CLI args parser function
** Config args parser function
** Implement Display for Args
** Args resolver
** GitHub README
* Release process
** Update release notes
Expand Down
7 changes: 6 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ pub struct Args {
pub config: Option<PathBuf>,
/// Print arguments and exit
pub arguments: bool,
/// Do not read any config file
pub noconfig: bool,
}

/// Arguments using Options to track CLI/config file/default values
Expand All @@ -57,6 +59,7 @@ pub struct OptionArgs {
pub wrapmin: Option<u8>,
pub config: Option<PathBuf>,
pub arguments: Option<bool>,
pub noconfig: Option<bool>,
}

/// Character to use for indentation
Expand Down Expand Up @@ -91,6 +94,7 @@ impl Default for OptionArgs {
wrapmin: Some(70),
config: None,
arguments: Some(false),
noconfig: Some(false),
}
}
}
Expand Down Expand Up @@ -122,6 +126,7 @@ impl Args {
wrapmin: args.wrapmin.unwrap(),
config: args.config,
arguments: args.arguments.unwrap(),
noconfig: args.noconfig.unwrap(),
}
}

Expand Down Expand Up @@ -225,7 +230,7 @@ impl fmt::Display for Args {
None => display_arg_line(f, "config", "None")?,
Some(c) => display_arg_line(f, "config", &c.display().to_string())?,
}
// Note we do not print the `arguments` field as it's not useful
// Do not print `arguments` or `noconfig` fields
Ok(())
}
}
5 changes: 5 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ pub fn get_cli_args() -> OptionArgs {
} else {
None
},
noconfig: if arg_matches.get_flag("noconfig") {
Some(true)
} else {
None
},
};
args
}
6 changes: 6 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@ fn get_cli_command() -> Command {
.action(SetTrue)
.help("Print arguments passed to tex-fmt and exit"),
)
.arg(
Arg::new("noconfig")
.long("noconfig")
.action(SetTrue)
.help("Do not read any config file"),
)
}
7 changes: 6 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const CONFIG: &str = "tex-fmt.toml";

/// Try finding a config file in various sources
fn resolve_config_path(args: &OptionArgs) -> Option<PathBuf> {
// Do not read config file
if args.noconfig == Some(true) {
return None;
};
// Named path passed as cli arg
if args.config.is_some() {
return args.config.clone();
Expand Down Expand Up @@ -113,7 +117,8 @@ pub fn get_config_args(args: &OptionArgs) -> Option<OptionArgs> {
.get("wrapmin")
.map(|x| x.as_integer().unwrap().try_into().unwrap()),
config: config_path,
arguments: config.get("arguments").map(|x| x.as_bool().unwrap()),
arguments: None,
noconfig: None,
};
Some(args)
}

0 comments on commit 9382eef

Please sign in to comment.