Skip to content

Commit 373e7de

Browse files
authored
Document the fluent-syntax bin files (#292)
1 parent 0a198ee commit 373e7de

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

fluent-syntax/src/bin/parser.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
//! This is a simple CLI utility to take in an FTL file and output the AST.
2+
//!
3+
//! ## View the `Debug` representation:
4+
//!
5+
//! From the root directory of the `fluent-rs` repo:
6+
//!
7+
//! ```sh
8+
//! cargo run --bin parser -- ./fluent-syntax/tests/fixtures/literal_expressions.ftl
9+
//! ```
10+
//!
11+
//! ## View the `json` representation:
12+
//!
13+
//! ```sh
14+
//! cargo run --bin parser --features json -- ./fluent-syntax/tests/fixtures/literal_expressions.ftl
15+
//! ```
16+
117
use fluent_syntax::parser::parse;
218
use std::env;
319
use std::fs::File;
@@ -13,7 +29,8 @@ fn read_file(path: &str) -> Result<String, io::Error> {
1329

1430
fn main() {
1531
let args: Vec<String> = env::args().collect();
16-
let source = read_file(args.get(1).expect("Pass an argument")).expect("Failed to fetch file");
32+
let source = read_file(args.get(1).expect("Pass a file path as the first argument"))
33+
.expect("Failed to fetch file");
1734

1835
let (ast, errors) = match parse(source.as_str()) {
1936
Ok(ast) => (ast, None),

fluent-syntax/src/bin/update_fixtures.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Run the `update_fixtures` binary after updating any of the `benches` `.ftl` fixtures.
2+
//! This will update the `.json` files used in reference tests.
3+
//!
4+
//! This file must be run from `{PROJECT_ROOT}/fluent-syntax`
5+
//!
6+
//! ```sh
7+
//! cargo run --bin update_fixtures --features="json"
8+
//! ```
19
use std::fs;
210
use std::io;
311

@@ -17,7 +25,9 @@ fn main() {
1725

1826
for sample in samples {
1927
let path = format!("./benches/{}.ftl", sample);
20-
let source = read_file(&path).unwrap();
28+
let source = read_file(&path).expect(
29+
"Could not read the benches file. Are you running this from the correct directory? It must be run from `{PROJECT_ROOT}/fluent-syntax`",
30+
);
2131
let ast = parse(source).unwrap();
2232
let target_json = serde_json::to_string_pretty(&ast).unwrap();
2333
let new_path = format!("./tests/fixtures/benches/{}.json", sample);

0 commit comments

Comments
 (0)