Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
finxxi committed Oct 7, 2024
1 parent 1c7dba9 commit 37e6f66
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
42 changes: 36 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
# 🚀 A Blazingly Fast Salesforce Apex Formatter

Afmt is a **Salesforce Apex Code Formatter** written in **Rust**! This tool formats your Apex code for consistency and readability. 🎯 It uses [tree-sitter apex parser](https://github.com/aheber/tree-sitter-sfapex) to traverse AST nodes.
Afmt is written in **Rust** 🦀.
It uses [tree-sitter apex parser](https://github.com/aheber/tree-sitter-sfapex) to traverse AST nodes.

Note: This is a project in its early phase, don't expect to use it in production code yet.
Project Project can be found in this section.
Note: This is a project in its early phase, don't expect to use it in production code yet.
Project progress can be found below.

# 🔧 Usage

Download the binary from the [release page](https://github.com/xixiaofinland/afmt/releases). It
supports Linux, MacOS, and Linux.

Run `afmt -h` to check the supported parameters.
Extract and run `afmt -h` to check the supported parameters.

```
Format Apex file v0.0.7
Usage: afmt [OPTIONS]
Options:
-f, --file <FILE> The relative path to the file to parse [default: test.cls]
-c, --config <CONFIG> Path to the .afmt.toml configuration file
-w, --write Write the formatted result back to the file
-h, --help Print help
-V, --version Print version
```

## Simplest use scenario:

- create a `test.cls` file next to binary
- create a `test.cls` file next to binary with Apex code
- run `afmt` to dry-check the format result
- run `afmt -w` to write the format result back to `test.cls`
- run `afmt -w` to write the format result into the file (`test.cls`)

```
» afmt
Result 0: Ok
public class Me {
public integer prop { get; set {
prop = value;
} }
}
Formatted content written back to: test.cls
Afmt completed successfully.
Execution time: 995.869┬╡s
```
<br>

# 📟 Project Progress
Expand Down
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ pub fn get_args() -> Args {
.expect("File path is required")
.to_string(),
config: matches.get_one::<String>("config").map(|s| s.to_string()),
write: matches.contains_id("write"),
write: matches.get_flag("write"),
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn main() {
}

fn run(args: Args) -> Result<()> {
eprintln!("gopro[5]: main.rs:32: args={:#?}", args);
let session =
Session::create_session_from_config(args.config.as_deref(), vec![args.path.clone()])?;
let results = format(session);
Expand Down

0 comments on commit 37e6f66

Please sign in to comment.