This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new 130066ded refactor(compiler): refactor fory compiler command line
(#3243)
130066ded is described below
commit 130066ded85fea00630bb57cdbc307e8bdf1ddf9
Author: Shawn Yang <[email protected]>
AuthorDate: Thu Jan 29 21:42:15 2026 +0800
refactor(compiler): refactor fory compiler command line (#3243)
## Why?
## What does this PR do?
refactor fory compiler command line: rename `fory compile` to `foryc`
## Related issues
#3099
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
---
AGENTS.md | 4 +-
compiler/README.md | 16 ++++----
compiler/fory_compiler/cli.py | 86 ++++++++++++++++++++++------------------
compiler/pyproject.toml | 2 +-
docs/compiler/compiler-guide.md | 54 ++++++++++++-------------
docs/compiler/flatbuffers-idl.md | 4 +-
docs/compiler/index.md | 4 +-
7 files changed, 89 insertions(+), 81 deletions(-)
diff --git a/AGENTS.md b/AGENTS.md
index 9f3ec0faf..f329427ec 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -413,8 +413,8 @@ Fory uses binary protocols for efficient serialization and
deserialization. Fory
- **Location**: `compiler/` contains the Fory compiler, parser, IR, and code
generators.
- **Install & CLI**:
- `cd compiler && pip install -e .`
- - `fory compile --help`
- - `fory compile schema.fdl --lang <langs> --output <dir>`
+ - `foryc --help`
+ - `foryc schema.fdl --lang <langs> --output <dir>`
- **Generated code**: Never edit generated files manually; update the
`.fdl`/`.proto`/`.fbs` and re-run the compiler.
- **IDL tests**: Use `integration_tests/idl_tests/generate_idl.py` for test
codegen.
- In `integration_tests/idl_tests`, keep package names aligned with the IDL
filename.
diff --git a/compiler/README.md b/compiler/README.md
index d71450881..c530caab3 100644
--- a/compiler/README.md
+++ b/compiler/README.md
@@ -61,19 +61,19 @@ message Cat [id=103] {
```bash
# Generate for all languages
-fory compile schema.fdl --output ./generated
+foryc schema.fdl --output ./generated
# Generate for specific languages
-fory compile schema.fdl --lang java,python --output ./generated
+foryc schema.fdl --lang java,python --output ./generated
# Override package name
-fory compile schema.fdl --package myapp.models --output ./generated
+foryc schema.fdl --package myapp.models --output ./generated
# Language-specific output directories (protoc-style)
-fory compile schema.fdl --java_out=./src/main/java --python_out=./python/src
+foryc schema.fdl --java_out=./src/main/java --python_out=./python/src
# Combine with other options
-fory compile schema.fdl --java_out=./gen --go_out=./gen/go -I ./proto
+foryc schema.fdl --java_out=./gen --go_out=./gen/go -I ./proto
```
### 3. Use Generated Code
@@ -394,7 +394,7 @@ struct Cat {
## CLI Reference
```
-fory compile [OPTIONS] FILES...
+foryc [OPTIONS] FILES...
Arguments:
FILES FDL files to compile
@@ -414,7 +414,7 @@ See the `examples/` directory for sample FDL files and
generated output.
```bash
# Compile the demo schema
-fory compile examples/demo.fdl --output examples/generated
+foryc examples/demo.fdl --output examples/generated
```
## Development
@@ -427,7 +427,7 @@ pip install -e .
python -m fory_compiler compile examples/demo.fdl
# Or use the installed command
-fory compile examples/demo.fdl
+foryc examples/demo.fdl
```
## License
diff --git a/compiler/fory_compiler/cli.py b/compiler/fory_compiler/cli.py
index 5069f795f..5b58ee11e 100644
--- a/compiler/fory_compiler/cli.py
+++ b/compiler/fory_compiler/cli.py
@@ -207,34 +207,32 @@ def resolve_go_output_dir(base_go_out: Path, schema:
Schema) -> Path:
def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
"""Parse command line arguments."""
parser = argparse.ArgumentParser(
- prog="fory",
+ prog="foryc",
description="Fory IDL compiler",
)
- subparsers = parser.add_subparsers(dest="command", help="Available
commands")
-
- # compile command
- compile_parser = subparsers.add_parser(
- "compile",
- help="Compile IDL files (.fdl, .proto, .fbs) to language-specific
code",
+ parser.add_argument(
+ "--scan-generated",
+ action="store_true",
+ help="Scan for generated files under the current directory",
)
- compile_parser.add_argument(
+ parser.add_argument(
"files",
- nargs="+",
+ nargs="*",
type=Path,
metavar="FILE",
help="IDL files to compile",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--lang",
type=str,
default="all",
help="Comma-separated list of target languages
(java,python,cpp,rust,go). Default: all",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--output",
"-o",
type=Path,
@@ -242,14 +240,14 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
help="Output directory. Default: ./generated",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--package",
type=str,
default=None,
help="Override package name from FDL file",
)
- compile_parser.add_argument(
+ parser.add_argument(
"-I",
"--proto_path",
"--import_path",
@@ -262,7 +260,7 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
)
# Language-specific output directories (protoc-style)
- compile_parser.add_argument(
+ parser.add_argument(
"--java_out",
type=Path,
default=None,
@@ -270,7 +268,7 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
help="Generate Java code in DST_DIR",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--python_out",
type=Path,
default=None,
@@ -278,7 +276,7 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
help="Generate Python code in DST_DIR",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--cpp_out",
type=Path,
default=None,
@@ -286,7 +284,7 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
help="Generate C++ code in DST_DIR",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--go_out",
type=Path,
default=None,
@@ -294,7 +292,7 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
help="Generate Go code in DST_DIR",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--rust_out",
type=Path,
default=None,
@@ -302,7 +300,7 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
help="Generate Rust code in DST_DIR",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--go_nested_type_style",
type=str,
default=None,
@@ -310,35 +308,31 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
help="Go nested type naming style: camelcase or underscore (default)",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--emit-fdl",
action="store_true",
help="Emit translated FDL (for non-FDL inputs) for debugging",
)
- compile_parser.add_argument(
+ parser.add_argument(
"--emit-fdl-path",
type=Path,
default=None,
help="Write translated FDL to this path (file or directory)",
)
- scan_parser = subparsers.add_parser(
- "scan-generated",
- help="Scan for generated files under the current directory",
- )
- scan_parser.add_argument(
+ parser.add_argument(
"--root",
type=Path,
default=Path("."),
help="Root directory to scan (default: current directory)",
)
- scan_parser.add_argument(
+ parser.add_argument(
"--relative",
action="store_true",
help="Print paths relative to the scan root",
)
- delete_group = scan_parser.add_mutually_exclusive_group()
+ delete_group = parser.add_mutually_exclusive_group()
delete_group.add_argument(
"--delete",
action="store_true",
@@ -353,6 +347,23 @@ def parse_args(args: Optional[List[str]] = None) ->
argparse.Namespace:
return parser.parse_args(args)
+def normalize_args(args: Optional[List[str]]) -> List[str]:
+ """Normalize args so compile is the default command."""
+ if args is None:
+ args = sys.argv[1:]
+ if not args:
+ return []
+ if args[0] in {"-h", "--help"}:
+ return args
+ if args[0] == "--scan-generated":
+ return args
+ if args[0] == "scan-generated":
+ return ["--scan-generated", *args[1:]]
+ if args[0] == "compile":
+ return args[1:]
+ return args
+
+
def get_languages(lang_arg: str) -> List[str]:
"""Parse the language argument into a list of languages."""
if lang_arg == "all":
@@ -656,20 +667,17 @@ def cmd_scan_generated(args: argparse.Namespace) -> int:
def main(args: Optional[List[str]] = None) -> int:
"""Main entry point."""
- parsed = parse_args(args)
-
- if parsed.command is None:
- print("Usage: fory <command> [options]", file=sys.stderr)
- print("Commands: compile, scan-generated", file=sys.stderr)
- print("Use 'fory <command> --help' for more information",
file=sys.stderr)
- return 1
+ parsed = parse_args(normalize_args(args))
- if parsed.command == "compile":
- return cmd_compile(parsed)
- if parsed.command == "scan-generated":
+ if parsed.scan_generated:
return cmd_scan_generated(parsed)
- return 0
+ if not parsed.files:
+ print("Usage: foryc [--scan-generated] [options] FILES...",
file=sys.stderr)
+ print("Use 'foryc --help' for more information", file=sys.stderr)
+ return 1
+
+ return cmd_compile(parsed)
if __name__ == "__main__":
diff --git a/compiler/pyproject.toml b/compiler/pyproject.toml
index 958c70463..28c6b074b 100644
--- a/compiler/pyproject.toml
+++ b/compiler/pyproject.toml
@@ -42,7 +42,7 @@ classifiers = [
keywords = ["fory", "serialization", "codegen", "idl", "compiler"]
[project.scripts]
-fory = "fory_compiler.cli:main"
+foryc = "fory_compiler.cli:main"
[project.urls]
Homepage = "https://github.com/apache/fory"
diff --git a/docs/compiler/compiler-guide.md b/docs/compiler/compiler-guide.md
index 983ccc2e4..8bba859bb 100644
--- a/docs/compiler/compiler-guide.md
+++ b/docs/compiler/compiler-guide.md
@@ -33,7 +33,7 @@ pip install -e .
### Verify Installation
```bash
-fory compile --help
+foryc --help
```
## Command Line Interface
@@ -41,11 +41,11 @@ fory compile --help
### Basic Usage
```bash
-fory compile [OPTIONS] FILES...
+foryc [OPTIONS] FILES...
```
```bash
-fory scan-generated [OPTIONS]
+foryc --scan-generated [OPTIONS]
```
### Options
@@ -65,25 +65,25 @@ fory scan-generated [OPTIONS]
### Scan Generated Files
-Use `scan-generated` to find files produced by the Fory compiler. The scanner
walks
+Use `--scan-generated` to find files produced by the Fory compiler. The
scanner walks
the tree recursively, skips `build/`, `target/`, and hidden directories, and
prints
each generated file as it is found.
```bash
# Scan current directory
-fory scan-generated
+foryc --scan-generated
# Scan a specific root
-fory scan-generated --root ./src
+foryc --scan-generated --root ./src
# Print paths relative to the scan root
-fory scan-generated --root ./src --relative
+foryc --scan-generated --root ./src --relative
# Delete scanned generated files
-fory scan-generated --root ./src --delete
+foryc --scan-generated --root ./src --delete
# Dry-run (scan and print only)
-fory scan-generated --root ./src --dry-run
+foryc --scan-generated --root ./src --dry-run
```
### Examples
@@ -91,63 +91,63 @@ fory scan-generated --root ./src --dry-run
**Compile for all languages:**
```bash
-fory compile schema.fdl
+foryc schema.fdl
```
**Compile for specific languages:**
```bash
-fory compile schema.fdl --lang java,python
+foryc schema.fdl --lang java,python
```
**Specify output directory:**
```bash
-fory compile schema.fdl --output ./src/generated
+foryc schema.fdl --output ./src/generated
```
**Override package name:**
```bash
-fory compile schema.fdl --package com.myapp.models
+foryc schema.fdl --package com.myapp.models
```
**Compile multiple files:**
```bash
-fory compile user.fdl order.fdl product.fdl --output ./generated
+foryc user.fdl order.fdl product.fdl --output ./generated
```
**Use import search paths:**
```bash
# Add a single import path
-fory compile src/main.fdl -I libs/common
+foryc src/main.fdl -I libs/common
# Add multiple import paths (repeated option)
-fory compile src/main.fdl -I libs/common -I libs/types
+foryc src/main.fdl -I libs/common -I libs/types
# Add multiple import paths (comma-separated)
-fory compile src/main.fdl -I libs/common,libs/types,third_party/
+foryc src/main.fdl -I libs/common,libs/types,third_party/
# Using --proto_path (protoc-compatible alias)
-fory compile src/main.fdl --proto_path=libs/common
+foryc src/main.fdl --proto_path=libs/common
# Mix all styles
-fory compile src/main.fdl -I libs/common,libs/types --proto_path third_party/
+foryc src/main.fdl -I libs/common,libs/types --proto_path third_party/
```
**Language-specific output directories (protoc-style):**
```bash
# Generate only Java code to a specific directory
-fory compile schema.fdl --java_out=./src/main/java
+foryc schema.fdl --java_out=./src/main/java
# Generate multiple languages to different directories
-fory compile schema.fdl --java_out=./java/gen --python_out=./python/src
--go_out=./go/gen
+foryc schema.fdl --java_out=./java/gen --python_out=./python/src
--go_out=./go/gen
# Combine with import paths
-fory compile schema.fdl --java_out=./gen/java -I proto/ -I common/
+foryc schema.fdl --java_out=./gen/java -I proto/ -I common/
```
When using `--{lang}_out` options:
@@ -172,7 +172,7 @@ import "common.fdl"; // Found if common.fdl is in the same
directory
```bash
# No -I needed for same-directory imports
-fory compile main.fdl
+foryc main.fdl
```
**Example project structure:**
@@ -188,7 +188,7 @@ project/
**Without `-I` (fails):**
```bash
-$ fory compile src/main.fdl
+$ foryc src/main.fdl
Import error: Import not found: common.fdl
Searched in: /project/src
```
@@ -196,7 +196,7 @@ Import error: Import not found: common.fdl
**With `-I` (succeeds):**
```bash
-$ fory compile src/main.fdl -I libs/
+$ foryc src/main.fdl -I libs/
Compiling src/main.fdl...
Resolved 1 import(s)
```
@@ -397,7 +397,7 @@ setup(
Add to your Go file:
```go
-//go:generate fory compile ../schema.fdl --lang go --output .
+//go:generate foryc ../schema.fdl --lang go --output .
package models
```
@@ -553,7 +553,7 @@ steps:
run: pip install ./compiler
- name: Generate Types
- run: fory compile fdl/*.fdl --output src/generated
+ run: foryc fdl/*.fdl --output src/generated
- name: Build
run: ./gradlew build
diff --git a/docs/compiler/flatbuffers-idl.md b/docs/compiler/flatbuffers-idl.md
index 638a4da49..471b97a1d 100644
--- a/docs/compiler/flatbuffers-idl.md
+++ b/docs/compiler/flatbuffers-idl.md
@@ -118,13 +118,13 @@ convention).
Compile a FlatBuffers schema directly:
```bash
-fory compile schema.fbs --lang java,python --output ./generated
+foryc schema.fbs --lang java,python --output ./generated
```
To inspect the translated FDL for debugging:
```bash
-fory compile schema.fbs --emit-fdl --emit-fdl-path ./translated
+foryc schema.fbs --emit-fdl --emit-fdl-path ./translated
```
## Generated Code Differences
diff --git a/docs/compiler/index.md b/docs/compiler/index.md
index 76c64c9d1..694419cc0 100644
--- a/docs/compiler/index.md
+++ b/docs/compiler/index.md
@@ -106,10 +106,10 @@ message Person [id=100] {
```bash
# Generate for all languages
-fory compile example.fdl --output ./generated
+foryc example.fdl --output ./generated
# Generate for specific languages
-fory compile example.fdl --lang java,python --output ./generated
+foryc example.fdl --lang java,python --output ./generated
```
### 4. Use Generated Code
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]