Add a --list-languages option

Fixes #292
add_libdifftastic
Wilfred Hughes 2022-09-02 11:41:05 +07:00
parent 40dfd9eb29
commit fd571c98a7
4 changed files with 23 additions and 1 deletions

@ -14,6 +14,9 @@ Fixed an issue with HCL language detection on `.workflow` files.
Fixed terminal width detection when only stderr is a TTY (e.g. when
using difftastic with git). This was broken in 0.34.
Added an option `--list-languages` which reports all the languages
supported, along with the extensions associated with them.
## 0.34 (released 27th August 2022)
### Build

@ -32,6 +32,7 @@ extern crate log;
use crate::diff::{dijkstra, unchanged};
use crate::display::hunks::{matched_pos_to_hunks, merge_adjacent};
use crate::parse::guess_language::LANG_EXTENSIONS;
use crate::parse::syntax;
use diff::changes::ChangeMap;
use diff::dijkstra::ExceededGraphLimit;
@ -126,6 +127,15 @@ fn main() {
}
}
}
Mode::ListLanguages => {
for (name, extensions) in LANG_EXTENSIONS {
print!("{:?}", name);
for extension in *extensions {
print!(" .{}", extension);
}
println!();
}
}
Mode::Diff {
graph_limit,
byte_limit,

@ -136,6 +136,10 @@ fn app() -> clap::Command<'static> {
.help("Override language detection. Inputs are assumed to have this file extension. When diffing directories, applies to all files.")
// TODO: support DFT_LANGUAGE for consistency
)
.arg(
Arg::new("list-languages").long("list-languages")
.help("Print the all the languages supported by difftastic, along with their extensions.")
)
.arg(
Arg::new("byte-limit").long("byte-limit")
.takes_value(true)
@ -191,6 +195,7 @@ pub enum Mode {
/// The path that we should display for the RHS file.
rhs_display_path: String,
},
ListLanguages,
DumpTreeSitter {
path: String,
language_override: Option<guess_language::Language>,
@ -220,6 +225,10 @@ pub fn parse_args() -> Mode {
None => None,
};
if matches.is_present("list-languages") {
return Mode::ListLanguages;
}
if let Some(path) = matches.value_of("dump-syntax") {
return Mode::DumpSyntax {
path: path.to_string(),

@ -64,7 +64,7 @@ pub enum Language {
Zig,
}
const LANG_EXTENSIONS: &'static [(Language, &[&str])] = &[
pub const LANG_EXTENSIONS: &'static [(Language, &[&str])] = &[
(
Bash,
&[