mirror of
https://github.com/storytold/cadcraft.git
synced 2026-11-30 22:10:12 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ad9dca7fd |
@@ -1,13 +1,13 @@
|
||||
# Structural rules for the command-line code (RFC-0012): lint/ast-grep's rule tests, then a scan.
|
||||
# Structural rules for the command-line code (RFC-0018): the shared rule sets of craft-common-actions, then a scan.
|
||||
# Seconds, no Rust build.
|
||||
name: ast-grep
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths: ["lint/ast-grep/**", "apps/cadcraft-cli/src/**", "apps/cadcraft/src/launch_args.rs", "apps/cadcraft/src/main.rs", ".github/workflows/ast-grep.yml"]
|
||||
paths: ["apps/cadcraft-cli/src/**", "apps/cadcraft/src/launch_args.rs", "apps/cadcraft/src/main.rs", ".github/workflows/ast-grep.yml"]
|
||||
pull_request:
|
||||
paths: ["lint/ast-grep/**", "apps/cadcraft-cli/src/**", "apps/cadcraft/src/launch_args.rs", "apps/cadcraft/src/main.rs", ".github/workflows/ast-grep.yml"]
|
||||
paths: ["apps/cadcraft-cli/src/**", "apps/cadcraft/src/launch_args.rs", "apps/cadcraft/src/main.rs", ".github/workflows/ast-grep.yml"]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
@@ -22,5 +22,7 @@ jobs:
|
||||
# Tracked at @main like the other shared workflows.
|
||||
uses: storytold/craft-common-actions/.github/workflows/ast-grep.yml@main
|
||||
with:
|
||||
config: lint/ast-grep/sgconfig.yml
|
||||
# No rules of its own: the shared RFC-0018 sets (rfc-0018-string-error is on, as it was here).
|
||||
config: ""
|
||||
shared-rules: rfc-0018 rfc-0018-string-error
|
||||
paths: apps/cadcraft-cli/src apps/cadcraft/src/launch_args.rs apps/cadcraft/src/main.rs
|
||||
|
||||
@@ -81,3 +81,4 @@ Paths and conventions:
|
||||
- Progress log: `ROADMAP.md`. `plan/` is an optional gitignored notebook.
|
||||
- Run with a control channel: `cargo run --release -p cadcraft -- --sample --control PORT`. Methods are in `crates/ui-egui/src/control.rs`, the protocol in `docs/control-protocol.md`. Headless: `cadcraft-cli run --sample --script 'LINE 0,0 10,10\n' --export out.png`, `cadcraft-cli info file.dxf`, `cadcraft-cli mcp`.
|
||||
- Docs: `ROADMAP.md`, `docs/gaps.md` (ranked work), `docs/target-app-parity.md`, `docs/roadmap.md`, `docs/contributors.md`.
|
||||
- Before pushing a change to `apps/cadcraft-cli` or its launch flags, run the command-line scan CI runs (RFC-0018 section 3): with a checkout of storytold/craft-common-actions next to this repository, `ast-grep scan --config ../craft-common-actions/actions/ast-grep/shared/rfc-0018/sgconfig.yml <paths>` and the same with `rfc-0018-string-error`, where `<paths>` are the `paths` in `.github/workflows/ast-grep.yml`.
|
||||
|
||||
@@ -280,7 +280,7 @@ To run LISP routines, scripts and alias files, or to drive CADCraft from your ow
|
||||
[docs/customization.md](docs/customization.md).
|
||||
|
||||
`cadcraft-cli --help` documents every subcommand and flag; exit codes, streams, environment
|
||||
variables and its RFC-0012 conventions are in [docs/cli.md](docs/cli.md).
|
||||
variables and its RFC-0018 conventions are in [docs/cli.md](docs/cli.md).
|
||||
|
||||
## Architecture
|
||||
|
||||
|
||||
+3
-6
@@ -2,7 +2,7 @@
|
||||
|
||||
`cadcraft-cli` is headless CADCraft: it reads, converts and exports drawings, runs scripts and
|
||||
commands, prints the command catalog and serves MCP. It follows
|
||||
[RFC-0012: Command-line conventions](https://github.com/storytold/craft-contrib/pull/18).
|
||||
[RFC-0018: Command-line conventions](https://github.com/storytold/craft-contrib/blob/main/rfcs/0018-cli-conventions.md).
|
||||
|
||||
`cadcraft-cli --help` and `cadcraft-cli help <subcommand>` (or `<subcommand> --help`) are the
|
||||
reference for every subcommand, flag and value; this page doesn't repeat them. Examples are in the
|
||||
@@ -47,7 +47,7 @@ substitutes lack the original's OS/2 cap height, and applies to every subcommand
|
||||
## Not followed yet
|
||||
|
||||
- **`CADCRAFT_CONFIG_DIR` is the one flag fallback where an empty variable doesn't count as
|
||||
unset** (RFC-0012 rule 1.7): empty (or `--config-dir ""`) means no settings folder, as it did
|
||||
unset** (RFC-0018 rule 1.7): empty (or `--config-dir ""`) means no settings folder, as it did
|
||||
before the port.
|
||||
- **No variable for `mcp --connect`.** Photocraft's `mcp --bridge` falls back to its
|
||||
`*_CONTROL_PORT` variable. Here an exported `CADCRAFT_CONTROL_PORT` would silently switch `mcp`
|
||||
@@ -57,10 +57,7 @@ substitutes lack the original's OS/2 cap height, and applies to every subcommand
|
||||
- **The `string-error` ast-grep rule** covers the CLI code only. The engine's file hooks
|
||||
(`cadcraft_engine::cmd::file::IoHooks`) still return `Result<_, String>`, so `install_io` maps
|
||||
errors to strings at that boundary.
|
||||
- **No AGENTS.md line for the ast-grep scan.** RFC-0012 asks an app's AGENTS.md to have coding
|
||||
agents run the scan before pushing (`ast-grep scan -c lint/ast-grep/sgconfig.yml`); CI runs it
|
||||
on every PR that touches the CLI code.
|
||||
- **`perf` prints a text table**, with no `--json` (whether text listings get one is an open
|
||||
question in RFC-0012).
|
||||
question in RFC-0018).
|
||||
- **Saves a command or script runs** (`--cmd 'saveas {…}'`, a script's `SAVEAS`) are the engine's
|
||||
and are not checked against the opened drawings; only `--save` and `--export` are.
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
id: args-os
|
||||
valid:
|
||||
- let code = photocraft_cli::run(std::env::args_os().skip(1), &mut out, &mut err);
|
||||
- "let args: Vec<OsString> = env::args_os().collect();"
|
||||
- |
|
||||
use std::env::args_os;
|
||||
fn main() { let a: Vec<_> = args_os().collect(); }
|
||||
- |
|
||||
fn args() -> Vec<String> { Vec::new() }
|
||||
fn main() { let a = args(); }
|
||||
invalid:
|
||||
- "let args: Vec<String> = std::env::args().collect();"
|
||||
- for a in env::args().skip(1) {}
|
||||
- |
|
||||
use std::env::args;
|
||||
fn main() { let a: Vec<String> = args().collect(); }
|
||||
- |
|
||||
use std::env::{args, var};
|
||||
fn main() { for a in args() {} }
|
||||
@@ -1,13 +0,0 @@
|
||||
id: clap-error-message
|
||||
valid:
|
||||
- cmd.error(ErrorKind::ArgumentConflict, UsageError::BridgeRoots)
|
||||
- cmd.error(ErrorKind::ArgumentConflict, Conflict { a, b })
|
||||
- sub.error(kind, self)
|
||||
- log.error("not a clap error")
|
||||
invalid:
|
||||
- cmd.error(ErrorKind::ArgumentConflict, "configure automation roots on the desktop app")
|
||||
- sub.error(ErrorKind::MissingRequiredArgument, format!("{flag} requires {transport}"))
|
||||
- sub.error(ErrorKind::ArgumentConflict, BRIDGE_ROOTS)
|
||||
- cmd.error(ErrorKind::InvalidValue, e.to_string())
|
||||
- cmd.error(ErrorKind::InvalidValue, String::from("bad value"))
|
||||
- clap::Error::raw(ErrorKind::InvalidValue, "bad value")
|
||||
@@ -1,47 +0,0 @@
|
||||
id: clap-error-message-variable
|
||||
valid:
|
||||
- |
|
||||
fn conflict(cmd: &mut Command, a: String, b: String) -> clap::Error {
|
||||
cmd.error(ErrorKind::ArgumentConflict, Conflict { a, b })
|
||||
}
|
||||
- |
|
||||
fn wrap(cmd: &mut Command, e: UsageError) -> clap::Error {
|
||||
cmd.error(ErrorKind::ValueValidation, e)
|
||||
}
|
||||
- |
|
||||
fn unrelated(cmd: &mut Command, e: UsageError) -> clap::Error {
|
||||
let shown = format!("{e}");
|
||||
eprintln!("{shown}");
|
||||
cmd.error(ErrorKind::ValueValidation, e)
|
||||
}
|
||||
- |
|
||||
fn cloned(cmd: &mut Command, e: &UsageError) -> clap::Error {
|
||||
let owned = e.to_owned();
|
||||
cmd.error(ErrorKind::ValueValidation, owned)
|
||||
}
|
||||
invalid:
|
||||
- |
|
||||
fn conflict(cmd: &mut Command, a: &str, b: &str) -> clap::Error {
|
||||
let message = format!("the argument '{a}' cannot be used with '{b}'");
|
||||
cmd.error(ErrorKind::ArgumentConflict, message)
|
||||
}
|
||||
- |
|
||||
fn bad(cmd: &mut Command, e: UsageError) -> clap::Error {
|
||||
let message = e.to_string();
|
||||
cmd.error(ErrorKind::ValueValidation, message)
|
||||
}
|
||||
- |
|
||||
fn typed(cmd: &mut Command, flag: &str) -> clap::Error {
|
||||
let message: String = flag.into();
|
||||
clap::Error::raw(ErrorKind::InvalidValue, message)
|
||||
}
|
||||
- |
|
||||
fn literal(cmd: &mut Command) -> clap::Error {
|
||||
let message = "bad value".to_owned();
|
||||
cmd.error(ErrorKind::InvalidValue, message)
|
||||
}
|
||||
- |
|
||||
fn from(cmd: &mut Command) -> clap::Error {
|
||||
let message = String::from("bad value");
|
||||
cmd.error(ErrorKind::InvalidValue, message)
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
id: string-error
|
||||
valid:
|
||||
- "fn parse(s: &str) -> Result<Port, PortError> { todo!() }"
|
||||
- "fn name() -> Option<String> { None }"
|
||||
- "fn ok() -> Result<String, PortError> { Ok(String::new()) }"
|
||||
- Err(PortError::Range)
|
||||
- Err(e)
|
||||
invalid:
|
||||
- "fn parse(s: &str) -> Result<Port, String> { todo!() }"
|
||||
- "type R = Result<(), String>;"
|
||||
- Err(format!("bad port {s}"))
|
||||
- Err(e.to_string())
|
||||
- Err(String::from("bad port"))
|
||||
- Err("bad port")
|
||||
@@ -1,21 +0,0 @@
|
||||
id: args-os
|
||||
language: rust
|
||||
severity: error
|
||||
message: std::env::args() panics on an argument that isn't valid Unicode
|
||||
note: |
|
||||
Read std::env::args_os() and let clap parse the OsStrings, so a Latin-1 file name reaches the
|
||||
command (or is a usage error) instead of aborting before anything is printed (photocraft#1108).
|
||||
rule:
|
||||
any:
|
||||
- pattern: std::env::args()
|
||||
- pattern: env::args()
|
||||
# A bare args() only where the file imports std::env::args, not any function named args.
|
||||
- all:
|
||||
- pattern: args()
|
||||
- inside:
|
||||
kind: source_file
|
||||
stopBy: end
|
||||
has:
|
||||
kind: use_declaration
|
||||
stopBy: end
|
||||
regex: std::env::(args\b|\{[^}]*\bargs\b)
|
||||
@@ -1,35 +0,0 @@
|
||||
id: clap-error-message-variable
|
||||
language: rust
|
||||
severity: error
|
||||
message: clap error built from a string held in a variable
|
||||
note: |
|
||||
The message was built with format!, .to_string(), String::from or a literal's .to_owned() a
|
||||
few lines up. Give it a variant on a
|
||||
#[derive(thiserror::Error)] enum instead, with the parts as fields, and pass the variant.
|
||||
rule:
|
||||
# In this order: the call binds $MSG, then the function must hold a `let` of that same name.
|
||||
all:
|
||||
- any:
|
||||
- pattern: $CMD.error($KIND, $MSG)
|
||||
- pattern: Error::raw($KIND, $MSG)
|
||||
- pattern: clap::Error::raw($KIND, $MSG)
|
||||
- inside:
|
||||
kind: function_item
|
||||
stopBy: end
|
||||
has:
|
||||
stopBy: end
|
||||
any:
|
||||
- pattern: let $MSG = format!($$$);
|
||||
- pattern: "let $MSG: String = $VAL;"
|
||||
- pattern: let $MSG = $SRC.to_string();
|
||||
- pattern: let $MSG = String::from($$$);
|
||||
# .to_owned() only on a string literal: on anything else it may clone a typed error.
|
||||
- all:
|
||||
- kind: let_declaration
|
||||
- regex: '=\s*"(?s:.*)"\s*\.to_owned\(\)\s*;?$'
|
||||
- has:
|
||||
field: pattern
|
||||
pattern: $MSG
|
||||
constraints:
|
||||
MSG:
|
||||
kind: identifier
|
||||
@@ -1,26 +0,0 @@
|
||||
id: clap-error-message
|
||||
language: rust
|
||||
severity: error
|
||||
message: clap error built from a string
|
||||
note: |
|
||||
Give the message a variant on a #[derive(thiserror::Error)] enum and pass the variant, e.g.
|
||||
`cmd.error(ErrorKind::ArgumentConflict, UsageError::BridgeRoots)`. A string literal, format!,
|
||||
.to_string() or a SCREAMING_CASE const keeps the message apart from the error's type.
|
||||
rule:
|
||||
any:
|
||||
- pattern: $CMD.error($KIND, $MSG)
|
||||
- pattern: Error::raw($KIND, $MSG)
|
||||
- pattern: clap::Error::raw($KIND, $MSG)
|
||||
constraints:
|
||||
MSG:
|
||||
any:
|
||||
- kind: string_literal
|
||||
- all:
|
||||
- kind: macro_invocation
|
||||
- regex: ^format!
|
||||
- all:
|
||||
- kind: identifier
|
||||
- regex: ^[A-Z][A-Z0-9_]*$
|
||||
- all:
|
||||
- kind: call_expression
|
||||
- regex: \.(to_string|to_owned)\(\)$|^String::from\(
|
||||
@@ -1,21 +0,0 @@
|
||||
id: string-error
|
||||
language: rust
|
||||
severity: error
|
||||
message: String as an error type
|
||||
note: |
|
||||
Return a #[derive(thiserror::Error)] enum, so a caller can match on what failed and the
|
||||
messages live with their variants.
|
||||
rule:
|
||||
any:
|
||||
- pattern:
|
||||
context: type T = Result<$OK, String>;
|
||||
selector: generic_type
|
||||
- pattern: Err(format!($$$))
|
||||
- pattern: Err($S.to_string())
|
||||
- pattern: Err(String::from($$$))
|
||||
- all:
|
||||
- pattern: Err($S)
|
||||
- has:
|
||||
kind: arguments
|
||||
has:
|
||||
kind: string_literal
|
||||
@@ -1,6 +0,0 @@
|
||||
# Structural rules for the command-line code (RFC-0012), run by .github/workflows/ast-grep.yml.
|
||||
# Each rule in rules/ has its cases in rule-tests/, which CI checks before the scan.
|
||||
ruleDirs:
|
||||
- rules
|
||||
testConfigs:
|
||||
- testDir: rule-tests
|
||||
Reference in New Issue
Block a user