Skip to content

Commit

Permalink
Merge pull request #34 from numtide/args-to-options
Browse files Browse the repository at this point in the history
change config from 'args' to 'options' to match formatters
  • Loading branch information
Rizary authored Feb 3, 2021
2 parents 7db5ebc + f3ea689 commit 42a8611
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ This section describes the integration between a single formatter and
full filenames can be passed. Eg: `[ "Makefile" ]`.

* `command`: A list of arguments to execute the formatter. This will be
composed with the `args` attribute during invocation. The first argument
composed with the `options` attribute during invocation. The first argument
is the name of the executable to run.

* `args`: A list of extra arguments to add to the command. This is typically
* `options`: A list of extra arguments to add to the command. This is typically
project-specific arguments.

NOTE: Formatters SHOULD adhere to the [formatter
Expand Down Expand Up @@ -135,7 +135,7 @@ Example:
In the `prjfmt.toml` file of the project:
```toml
[formatters.ormolu]
args = [
options = [
"--ghc-opt", "-XBangPatterns",
"--ghc-opt", "-XPatternSynonyms",
]
Expand All @@ -146,7 +146,7 @@ contains:
```toml
command = ["ormolu", "--mode", "inplace"]
files = ["*.hs"]
args = []
options = []
```
The project will first load `prjfmt.toml`, take note of the ormolu formatter,
Expand All @@ -157,12 +157,12 @@ this in their config:
[formatters.ormolu]
command = ["ormolu", "--mode", "inplace"]
files = ["*.hs"]
args = [
options = [
"--ghc-opt", "-XBangPatterns",
"--check-idempotence"
]
```
Note how the empty ormolu `args` got overwritten by the project `args`.
Note how the empty ormolu `options` got overwritten by the project `options`.
## Related projects
Expand Down
4 changes: 2 additions & 2 deletions examples/monorepo/prjfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
files = "*.hs" # / "*.hs" / "Makefile" mandatory
excludes = [ "haskell/" ] # blacklisted folder/files.
command = "ormolu"
args = [
options = [
"--ghc-opt", "-XBangPatterns",
"--ghc-opt", "-XPatternSynonyms",
"--ghc-opt", "-XTypeApplications",
Expand All @@ -16,4 +16,4 @@ files = [ "*.rs" ]
includes = [ "rust/" ]
excludes = []
command = "cargo"
args = [ "fmt", "--" ]
options = [ "fmt", "--" ]
2 changes: 1 addition & 1 deletion src/command/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn init_prjfmt(path: Option<PathBuf>) -> anyhow::Result<()> {
includes = [ "*.<language-extension>" ]
excludes = []
command = ""
args = []
options = []
"#,
)
.with_context(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn check_prjfmt(
.map(|(a, b)| {
Ok(CmdContext {
command: a.command.clone(),
args: a.args.clone(),
options: a.options.clone(),
metadata: a.metadata.difference(&b.metadata).cloned().collect(),
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/formatters/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn create_prjfmt_manifest(
let prjfmt = cmd.command;
let manifest = CmdContext {
command: prjfmt.to_string(),
args: cmd.args,
options: cmd.options,
metadata: cmd.metadata,
};
(prjfmt.to_string(), manifest)
Expand Down
10 changes: 5 additions & 5 deletions src/formatters/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn run_prjfmt(cwd: PathBuf, cache_dir: PathBuf) -> anyhow::Result<()> {
.par_iter()
.flat_map(|c| {
c.metadata.par_iter().cloned().map(move |m| {
let arg = &c.args;
let arg = &c.options;
let cmd_arg = &c.command;
let path = &m.path;
cmd!("{cmd_arg} {arg...} {path}").output()
Expand All @@ -87,7 +87,7 @@ pub fn run_prjfmt(cwd: PathBuf, cache_dir: PathBuf) -> anyhow::Result<()> {
if c.command == octx.command {
CmdContext {
command: c.command.clone(),
args: c.args.clone(),
options: c.options.clone(),
metadata: octx.metadata.union(&c.metadata).cloned().collect(),
}
} else {
Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn create_command_context(prjfmt_toml: &PathBuf) -> Result<Vec<CmdContext>>
)?;
Ok(CmdContext {
command: config.command.clone().unwrap_or_default(),
args: config.args.clone().unwrap_or_default(),
options: config.options.clone().unwrap_or_default(),
metadata: path_to_filemeta(list_files)?,
})
})
Expand All @@ -241,7 +241,7 @@ pub struct FmtConfig {
/// Command formatter to run
pub command: Option<String>,
/// Argument for formatter
pub args: Option<Vec<String>>,
pub options: Option<Vec<String>>,
}

/// File extensions can be single string (e.g. "*.hs") or
Expand Down Expand Up @@ -273,7 +273,7 @@ pub struct CmdContext {
/// formatter command to run
pub command: String,
/// formatter arguments or flags
pub args: Vec<String>,
pub options: Vec<String>,
/// formatter target path
pub metadata: BTreeSet<FileMeta>,
}
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn main() {
}

fn run() -> anyhow::Result<()> {
let args = Cli::from_args();
let options = Cli::from_args();

CLOG.set_log_level(args.log_level);
CLOG.set_log_level(options.log_level);

if args.quiet {
if options.quiet {
CLOG.set_quiet(true);
}

run_cli(args)?;
run_cli(options)?;

Ok(())
}

0 comments on commit 42a8611

Please sign in to comment.