1use argh::FromArgs;
2
3pub const CALCIT_VERSION: &str = env!("CARGO_PKG_VERSION");
4
5#[derive(FromArgs, PartialEq, Debug, Clone)]
6pub struct ToplevelCalcit {
8 #[argh(subcommand)]
9 pub subcommand: Option<CalcitCommand>,
10 #[argh(switch, short = 'w')]
12 pub watch: bool,
13 #[argh(switch)]
15 pub check_only: bool,
16 #[argh(switch)]
18 pub incremental: bool,
19 #[argh(switch)]
21 pub keep_going: bool,
22 #[argh(switch)]
24 pub all_defs: bool,
25 #[argh(option)]
27 pub ns: Vec<String>,
28 #[argh(switch, long = "static-core")]
30 pub static_core: bool,
31 #[argh(switch)]
33 pub deps: bool,
34 #[argh(switch, long = "summary-only")]
36 pub summary_only: bool,
37 #[argh(option, default = "String::from(\"human\")")]
39 pub format: String,
40 #[argh(switch)]
42 pub disable_stack: bool,
43 #[argh(switch)]
45 pub skip_arity_check: bool,
46 #[argh(switch)]
48 pub warn_dyn_method: bool,
49 #[argh(switch)]
51 pub no_proof_audit: bool,
52 #[argh(switch, long = "deny-migration-warnings")]
54 pub deny_migration_warnings: bool,
55 #[argh(switch)]
57 pub trace_ffi: bool,
58 #[argh(option, default = "String::from(\"js-out/\")")]
60 pub emit_path: String,
61 #[argh(option)]
63 pub init_fn: Option<String>,
64 #[argh(option)]
66 pub reload_fn: Option<String>,
67 #[argh(option)]
69 pub entry: Option<String>,
70 #[argh(switch)]
71 pub reload_libs: bool,
73 #[argh(option)]
74 pub watch_dir: Option<String>,
76 #[argh(positional, default = "String::from(calcit_core::DEFAULT_SNAPSHOT_FILE)")]
78 pub input: String,
79 #[argh(switch, short = 'v')]
81 pub version: bool,
82 #[argh(switch)]
84 pub verbose: bool,
85 #[argh(switch)]
87 pub macro_metrics: bool,
88 #[argh(switch)]
90 pub ffi_metrics: bool,
91 #[argh(option, default = "60")]
93 pub timeout: u64,
94 #[argh(switch)]
96 pub tips: bool,
97 #[argh(option)]
99 pub tips_level: Option<String>,
100 #[argh(option, default = "String::from(\"summary\")")]
102 pub cursor_after: String,
103}
104
105#[derive(FromArgs, PartialEq, Debug, Clone)]
106#[argh(subcommand)]
107pub enum CalcitCommand {
108 EmitJs(EmitJsCommand),
110 EmitWasm(EmitWasmCommand),
112 EmitWasi(EmitWasiCommand),
114 EmitIr(EmitIrCommand),
116 Eval(EvalCommand),
118 Test(TestCommand),
120 Fix(FixCommand),
122 Analyze(AnalyzeCommand),
124 Query(QueryCommand),
126 Docs(DocsCommand),
128 Cirru(CirruCommand),
130 Edit(EditCommand),
132 Tree(TreeCommand),
134 Cursor(CursorCommand),
136 Config(ConfigCommand),
138 Ffi(FfiCommand),
140}
141
142#[derive(FromArgs, PartialEq, Debug, Clone)]
143#[argh(
144 subcommand,
145 name = "fix",
146 note = "Project upgrades follow one ordered sequence: run `calcit docs agents 项目升级入口` (embedded in this CLI), then `calcit docs read upgrade.md '当前升级闭环'` from a guidebook checked out at the same release tag."
147)]
148pub struct FixCommand {
150 #[argh(switch)]
152 pub apply: bool,
153 #[argh(switch, long = "dry-run")]
155 pub dry_run: bool,
156 #[argh(switch, long = "include-attached")]
158 pub include_attached: bool,
159 #[argh(option, default = "String::from(\"human\")")]
161 pub format: String,
162 #[argh(option)]
164 pub ns: Option<String>,
165 #[argh(option, long = "def")]
167 pub definition: Option<String>,
168 #[argh(option)]
170 pub rule: Option<String>,
171 #[argh(option)]
173 pub preset: Option<String>,
174 #[argh(option)]
176 pub pattern: Option<String>,
177 #[argh(option, long = "replace")]
179 pub replacement: Option<String>,
180 #[argh(option)]
182 pub workflow: Option<String>,
183 #[argh(switch)]
185 pub verify: bool,
186 #[argh(switch, long = "summary-only")]
188 pub summary_only: bool,
189 #[argh(option, long = "to")]
191 pub replacement_name: Option<String>,
192 #[argh(option)]
194 pub at: Option<String>,
195 #[argh(option, long = "expect-revision")]
197 pub expect_revision: Option<String>,
198 #[argh(switch, long = "allow-dirty")]
200 pub allow_dirty: bool,
201 #[argh(switch, long = "allow-no-vcs")]
203 pub allow_no_vcs: bool,
204}
205
206#[derive(FromArgs, PartialEq, Debug, Clone)]
207#[argh(subcommand, name = "ffi")]
208pub struct FfiCommand {
210 #[argh(subcommand)]
211 pub subcommand: FfiSubcommand,
212}
213
214#[derive(FromArgs, PartialEq, Debug, Clone)]
215#[argh(subcommand)]
216pub enum FfiSubcommand {
217 Export(FfiExportCommand),
219}
220
221#[derive(FromArgs, PartialEq, Debug, Clone)]
222#[argh(subcommand, name = "export")]
223pub struct FfiExportCommand {
225 #[argh(option, default = "String::from(\"native\")")]
227 pub boundary: String,
228 #[argh(option)]
230 pub format: Option<String>,
231 #[argh(option)]
233 pub ns: Option<String>,
234}
235
236#[derive(FromArgs, PartialEq, Debug, Clone)]
241#[argh(subcommand, name = "test")]
242pub struct TestCommand {
243 #[argh(positional)]
245 pub target: Option<String>,
246 #[argh(option)]
248 pub name: Option<String>,
249 #[argh(option)]
251 pub tag: Vec<String>,
252 #[argh(option)]
254 pub exclude_tag: Vec<String>,
255 #[argh(option)]
257 pub affected: Vec<String>,
258 #[argh(switch)]
260 pub list: bool,
261 #[argh(switch)]
263 pub fail_fast: bool,
264 #[argh(switch)]
266 pub require_match: bool,
267 #[argh(switch)]
269 pub summary_only: bool,
270 #[argh(option, default = "String::from(\"human\")")]
272 pub format: String,
273}
274
275#[derive(FromArgs, PartialEq, Debug, Clone)]
277#[argh(subcommand, name = "js")]
278pub struct EmitJsCommand {
279 #[argh(switch, short = 'w')]
281 pub watch: bool,
282 #[argh(switch)]
284 pub check_only: bool,
285}
286
287#[derive(FromArgs, PartialEq, Debug, Clone)]
289#[argh(subcommand, name = "wasm")]
290pub struct EmitWasmCommand {
291 #[argh(positional)]
293 pub input: Option<String>,
294 #[argh(option)]
296 pub emit_path: Option<String>,
297 #[argh(option)]
299 pub entry: Option<String>,
300 #[argh(option)]
302 pub init_fn: Option<String>,
303 #[argh(option)]
305 pub reload_fn: Option<String>,
306 #[argh(option, default = "String::from(\"native\")")]
308 pub boundary: String,
309 #[argh(switch)]
311 pub check_only: bool,
312}
313
314#[derive(FromArgs, PartialEq, Debug, Clone)]
316#[argh(subcommand, name = "wasi")]
317pub struct EmitWasiCommand {
318 #[argh(positional)]
320 pub input: Option<String>,
321 #[argh(option)]
323 pub emit_path: Option<String>,
324 #[argh(option)]
326 pub entry: Option<String>,
327 #[argh(option)]
329 pub init_fn: Option<String>,
330 #[argh(option)]
332 pub reload_fn: Option<String>,
333 #[argh(option, default = "String::from(\"component\")")]
335 pub boundary: String,
336 #[argh(option, default = "String::from(\"command\")")]
338 pub world: String,
339 #[argh(switch)]
341 pub check_only: bool,
342}
343
344#[derive(FromArgs, PartialEq, Debug, Clone)]
346#[argh(subcommand, name = "ir")]
347pub struct EmitIrCommand {
348 #[argh(switch, short = 'w')]
350 pub watch: bool,
351 #[argh(switch)]
353 pub sources_only: bool,
354}
355
356#[derive(FromArgs, PartialEq, Debug, Clone)]
358#[argh(subcommand, name = "eval")]
359pub struct EvalCommand {
360 #[argh(positional)]
362 pub snippet: Option<String>,
363 #[argh(switch)]
365 pub stdin: bool,
366 #[argh(option)]
368 pub dep: Vec<String>,
369}
370
371#[derive(FromArgs, PartialEq, Debug, Clone)]
376#[argh(subcommand, name = "analyze")]
377pub struct AnalyzeCommand {
379 #[argh(subcommand)]
380 pub subcommand: AnalyzeSubcommand,
381}
382
383#[derive(FromArgs, PartialEq, Debug, Clone)]
384#[argh(subcommand)]
385pub enum AnalyzeSubcommand {
386 CallGraph(CallGraphCommand),
388 ProgramDiff(ProgramDiffCommand),
390 CheckExamples(CheckExamplesCommand),
392 WeakTypes(WeakTypesCommand),
394 Verify(VerifyCommand),
396}
397
398#[derive(FromArgs, PartialEq, Debug, Clone)]
400#[argh(subcommand, name = "verify")]
401pub struct VerifyCommand {
402 #[argh(option)]
404 pub profile: String,
405 #[argh(option, default = "String::from(\"human\")")]
407 pub format: String,
408}
409
410#[derive(PartialEq, Debug, Clone)]
412pub struct CheckPublicCommand {
413 pub ns: Vec<String>,
415 pub format: String,
417 pub deps: bool,
419 pub summary_only: bool,
421 pub static_core: bool,
423}
424
425#[derive(PartialEq, Debug, Clone)]
427pub struct CheckTypesCommand {
428 pub ns: Option<String>,
430 pub ns_prefix: Option<String>,
432 pub only: Option<String>,
434 pub format: String,
436 pub deps: bool,
438 pub summary_only: bool,
440 pub incremental: bool,
442}
443
444#[derive(FromArgs, PartialEq, Debug, Clone)]
446#[argh(subcommand, name = "weak-types")]
447pub struct WeakTypesCommand {
448 #[argh(option)]
450 pub ns: Option<String>,
451 #[argh(option)]
453 pub ns_prefix: Option<String>,
454 #[argh(option)]
456 pub only: Option<String>,
457 #[argh(option, long = "coverage-level")]
459 pub coverage_level: Option<String>,
460 #[argh(option)]
462 pub intent: Option<String>,
463 #[argh(option, default = "String::from(\"human\")")]
465 pub format: String,
466 #[argh(switch)]
468 pub deps: bool,
469 #[argh(switch, long = "ffi-evidence")]
471 pub ffi_evidence: bool,
472 #[argh(switch, long = "schema-evidence")]
474 pub schema_evidence: bool,
475 #[argh(switch, long = "summary-only")]
477 pub summary_only: bool,
478 #[argh(switch)]
480 pub incremental: bool,
481}
482
483#[derive(PartialEq, Debug, Clone)]
485pub struct DynamicMethodsCommand {
486 pub format: String,
488 pub deps: bool,
490 pub summary_only: bool,
492 pub incremental: bool,
494}
495
496#[derive(PartialEq, Debug, Clone)]
498pub struct DeprecatedCommand {
499 pub ns: Option<String>,
501 pub ns_prefix: Option<String>,
503 pub format: String,
505 pub deps: bool,
507 pub summary_only: bool,
509}
510
511#[derive(FromArgs, PartialEq, Debug, Clone)]
513#[argh(subcommand, name = "check-examples")]
514pub struct CheckExamplesCommand {
515 #[argh(option)]
517 pub ns: String,
518 #[argh(option, long = "def")]
520 pub definition: Option<String>,
521 #[argh(switch)]
523 pub js: bool,
524}
525
526#[derive(FromArgs, PartialEq, Debug, Clone)]
528#[argh(subcommand, name = "call-graph")]
529pub struct CallGraphCommand {
530 #[argh(option)]
532 pub root: Option<String>,
533 #[argh(option)]
535 pub ns_prefix: Option<String>,
536 #[argh(switch)]
538 pub include_core: bool,
539 #[argh(option)]
541 pub max_depth: Option<usize>,
542 #[argh(switch)]
544 pub show_unused: bool,
545 #[argh(option, default = "String::from(\"text\")")]
547 pub format: String,
548 #[argh(switch)]
550 pub counts: bool,
551 #[argh(option)]
553 pub sort: Option<String>,
554 #[argh(option)]
556 pub diff: Option<String>,
557 #[argh(switch)]
559 pub effects: bool,
560 #[argh(option)]
562 pub detail: Option<String>,
563 #[argh(option)]
565 pub color: Option<bool>,
566}
567
568#[derive(PartialEq, Debug, Clone)]
570pub struct EffectsGraphCommand {
571 pub root: Option<String>,
573 pub ns_prefix: Option<String>,
575 pub include_core: bool,
577 pub max_depth: usize,
579 pub format: String,
581 pub detail: String,
583 pub color: bool,
585}
586
587#[derive(PartialEq, Debug, Clone)]
589pub struct CallGraphDiffCommand {
590 pub git_ref: String,
592 pub root: Option<String>,
594 pub ns_prefix: Option<String>,
596 pub include_core: bool,
598 pub max_depth: usize,
600}
601
602#[derive(PartialEq, Debug, Clone)]
604pub struct CountCallsCommand {
605 pub root: Option<String>,
607 pub ns_prefix: Option<String>,
609 pub include_core: bool,
611 pub format: String,
613 pub sort: String,
615}
616
617#[derive(FromArgs, PartialEq, Debug, Clone)]
620#[argh(subcommand, name = "program-diff")]
621pub struct ProgramDiffCommand {
622 #[argh(positional)]
624 pub git_ref: String,
625 #[argh(option)]
628 pub base: Option<String>,
629 #[argh(option)]
631 pub def: Option<String>,
632 #[argh(option, default = "String::from(\"human\")")]
634 pub format: String,
635 #[argh(switch)]
637 pub fail_on_widening: bool,
638}
639
640#[derive(FromArgs, PartialEq, Debug, Clone)]
645#[argh(subcommand, name = "query")]
646pub struct QueryCommand {
648 #[argh(subcommand)]
649 pub subcommand: QuerySubcommand,
650}
651
652#[derive(FromArgs, PartialEq, Debug, Clone)]
653#[argh(subcommand)]
654pub enum QuerySubcommand {
655 Ns(QueryNsCommand),
657 Defs(QueryDefsCommand),
659 Config(QueryConfigCommand),
661 Error(QueryErrorCommand),
663 Def(QueryDefCommand),
665 Find(QueryFindCommand),
667 Usages(QueryUsagesCommand),
669 Search(QuerySearchCommand),
671 SearchExpr(QuerySearchExprCommand),
673 Schema(QuerySchemaCommand),
675 Type(QueryTypeCommand),
677 TypeAt(QueryTypeAtCommand),
679 Context(QueryContextCommand),
681}
682
683#[derive(FromArgs, PartialEq, Debug, Clone)]
684#[argh(subcommand, name = "schema")]
685pub struct QuerySchemaCommand {
687 #[argh(positional)]
689 pub target: String,
690 #[argh(option, default = "String::from(\"human\")")]
692 pub format: String,
693}
694
695#[derive(FromArgs, PartialEq, Debug, Clone)]
696#[argh(subcommand, name = "type")]
697pub struct QueryTypeCommand {
699 #[argh(positional)]
701 pub target: String,
702 #[argh(option, default = "String::from(\"human\")")]
704 pub format: String,
705}
706
707#[derive(FromArgs, PartialEq, Debug, Clone)]
708#[argh(subcommand, name = "type-at")]
709pub struct QueryTypeAtCommand {
711 #[argh(positional)]
713 pub target: String,
714 #[argh(option)]
716 pub path: String,
717 #[argh(option, default = "String::from(\"human\")")]
719 pub format: String,
720}
721
722#[derive(FromArgs, PartialEq, Debug, Clone)]
723#[argh(subcommand, name = "context")]
724pub struct QueryContextCommand {
726 #[argh(positional)]
728 pub target: String,
729 #[argh(option, default = "6000")]
731 pub budget: usize,
732 #[argh(option, default = "String::from(\"human\")")]
734 pub format: String,
735 #[argh(switch)]
737 pub deps: bool,
738 #[argh(option, default = "12")]
740 pub dependency_limit: usize,
741 #[argh(option, default = "8")]
743 pub usage_limit: usize,
744 #[argh(option, default = "3")]
746 pub example_limit: usize,
747 #[argh(option, default = "3")]
749 pub test_limit: usize,
750 #[argh(switch)]
752 pub include_core: bool,
753}
754
755#[derive(FromArgs, PartialEq, Debug, Clone)]
756#[argh(subcommand, name = "ns")]
757pub struct QueryNsCommand {
759 #[argh(positional)]
761 pub namespace: Option<String>,
762 #[argh(switch)]
764 pub deps: bool,
765 #[argh(option, default = "String::from(\"human\")")]
767 pub format: String,
768}
769
770#[derive(FromArgs, PartialEq, Debug, Clone)]
771#[argh(subcommand, name = "defs")]
772pub struct QueryDefsCommand {
774 #[argh(positional)]
776 pub namespace: String,
777 #[argh(option)]
779 pub tag: Option<String>,
780 #[argh(switch)]
782 pub signatures: bool,
783 #[argh(option, default = "String::from(\"human\")")]
785 pub format: String,
786}
787
788#[derive(FromArgs, PartialEq, Debug, Clone)]
791#[argh(subcommand, name = "config")]
792pub struct QueryConfigCommand {
794 #[argh(option, default = "String::from(\"human\")")]
796 pub format: String,
797}
798
799#[derive(FromArgs, PartialEq, Debug, Clone)]
800#[argh(subcommand, name = "error")]
801pub struct QueryErrorCommand {}
803
804#[derive(FromArgs, PartialEq, Debug, Clone)]
805#[argh(subcommand, name = "def")]
806pub struct QueryDefCommand {
808 #[argh(positional)]
810 pub target: String,
811 #[argh(option, default = "String::from(\"human\")")]
813 pub format: String,
814 #[argh(switch)]
816 pub summary: bool,
817 #[argh(option)]
819 pub only: Option<String>,
820 #[argh(option, default = "56")]
822 pub chunk_target_nodes: usize,
823 #[argh(option, default = "68")]
825 pub chunk_max_nodes: usize,
826 #[argh(option, default = "88")]
828 pub chunk_trigger_nodes: usize,
829 #[argh(option, default = "2048")]
831 pub chunk_trigger_bytes: usize,
832 #[argh(switch)]
834 pub raw: bool,
835}
836
837#[derive(FromArgs, PartialEq, Debug, Clone)]
838#[argh(subcommand, name = "find")]
839pub struct QueryFindCommand {
841 #[argh(positional)]
843 pub symbol: String,
844 #[argh(switch)]
846 pub deps: bool,
847 #[argh(switch)]
849 pub exact: bool,
850 #[argh(option, default = "20")]
852 pub limit: usize,
853 #[argh(option, long = "detail-offset", default = "0")]
855 pub detail_offset: usize,
856}
857
858#[derive(FromArgs, PartialEq, Debug, Clone)]
859#[argh(subcommand, name = "usages")]
860pub struct QueryUsagesCommand {
862 #[argh(positional)]
864 pub target: String,
865 #[argh(switch)]
867 pub deps: bool,
868 #[argh(option, long = "detail-offset", default = "0")]
870 pub detail_offset: usize,
871}
872
873#[derive(FromArgs, PartialEq, Debug, Clone)]
874#[argh(subcommand, name = "search")]
875pub struct QuerySearchCommand {
877 #[argh(positional)]
879 pub pattern: String,
880 #[argh(option, long = "filter")]
882 pub filter: Option<String>,
883 #[argh(switch)]
885 pub exact: bool,
886 #[argh(switch, long = "regex")]
888 pub regex: bool,
889 #[argh(option, default = "0")]
891 pub max_depth: usize,
892 #[argh(option, long = "start-path")]
894 pub start_path: Option<String>,
895 #[argh(option, long = "entry")]
897 pub entry: Option<String>,
898 #[argh(option, default = "String::from(\"all\")")]
900 pub source: String,
901 #[argh(option, long = "detail-offset", default = "0")]
903 pub detail_offset: usize,
904 #[argh(switch, long = "parent-path")]
906 pub parent_path: bool,
907 #[argh(option, default = "String::from(\"human\")")]
909 pub format: String,
910 #[argh(option, long = "set-cursor")]
912 pub set_cursor: Option<usize>,
913}
914
915#[derive(FromArgs, PartialEq, Debug, Clone)]
916#[argh(subcommand, name = "search-expr")]
917pub struct QuerySearchExprCommand {
919 #[argh(positional)]
921 pub pattern: String,
922 #[argh(option, long = "filter")]
924 pub filter: Option<String>,
925 #[argh(switch)]
927 pub exact: bool,
928 #[argh(option, default = "0")]
930 pub max_depth: usize,
931 #[argh(option, long = "start-path")]
933 pub start_path: Option<String>,
934 #[argh(switch)]
936 pub json: bool,
937 #[argh(option, long = "entry")]
939 pub entry: Option<String>,
940 #[argh(option, long = "detail-offset", default = "0")]
942 pub detail_offset: usize,
943 #[argh(option, default = "String::from(\"human\")")]
945 pub format: String,
946 #[argh(option, long = "set-cursor")]
948 pub set_cursor: Option<usize>,
949}
950
951#[derive(FromArgs, PartialEq, Debug, Clone)]
956#[argh(subcommand, name = "docs")]
957pub struct DocsCommand {
959 #[argh(subcommand)]
960 pub subcommand: DocsSubcommand,
961}
962
963#[derive(FromArgs, PartialEq, Debug, Clone)]
964#[argh(subcommand)]
965pub enum DocsSubcommand {
966 Scopes(DocsScopesCommand),
968 RemoteLibs(DocsRemoteLibsCommand),
970 Search(DocsSearchCommand),
972 List(DocsListCommand),
974 Sections(DocsSectionsCommand),
976 Read(DocsReadCommand),
978 Agents(DocsAgentsCommand),
980 CheckMd(DocsCheckMdCommand),
982 FormatMd(DocsFormatMdCommand),
984}
985
986#[derive(FromArgs, PartialEq, Debug, Clone)]
987#[argh(subcommand, name = "scopes")]
988pub struct DocsScopesCommand {}
990
991#[derive(FromArgs, PartialEq, Debug, Clone)]
992#[argh(subcommand, name = "remote-libs")]
993pub struct DocsRemoteLibsCommand {
995 #[argh(subcommand)]
996 pub subcommand: Option<LibsSubcommand>,
997}
998
999#[derive(FromArgs, PartialEq, Debug, Clone)]
1000#[argh(subcommand, name = "search")]
1001pub struct DocsSearchCommand {
1003 #[argh(positional)]
1005 pub keyword: String,
1006 #[argh(option, default = "5")]
1008 pub context: usize,
1009 #[argh(option)]
1011 pub filename: Option<String>,
1012 #[argh(option)]
1014 pub module: Option<String>,
1015 #[argh(switch, long = "summary")]
1017 pub summary: bool,
1018}
1019
1020#[derive(FromArgs, PartialEq, Debug, Clone)]
1021#[argh(subcommand, name = "list")]
1022pub struct DocsListCommand {
1024 #[argh(option)]
1026 pub module: Option<String>,
1027}
1028
1029#[derive(FromArgs, PartialEq, Debug, Clone)]
1030#[argh(subcommand, name = "sections")]
1031pub struct DocsSectionsCommand {
1033 #[argh(positional)]
1035 pub filename: String,
1036 #[argh(option)]
1038 pub module: Option<String>,
1039 #[argh(switch)]
1041 pub with_lines: bool,
1042}
1043
1044#[derive(FromArgs, PartialEq, Debug, Clone)]
1045#[argh(subcommand, name = "read")]
1046pub struct DocsReadCommand {
1048 #[argh(positional)]
1050 pub filename: String,
1051 #[argh(positional)]
1053 pub headings: Vec<String>,
1054 #[argh(switch)]
1056 pub no_subheadings: bool,
1057 #[argh(switch)]
1059 pub full: bool,
1060 #[argh(switch)]
1062 pub with_lines: bool,
1063 #[argh(option)]
1065 pub module: Option<String>,
1066 #[argh(option)]
1068 pub start: Option<usize>,
1069 #[argh(option)]
1071 pub lines: Option<usize>,
1072}
1073
1074#[derive(FromArgs, PartialEq, Debug, Clone)]
1075#[argh(subcommand, name = "agents")]
1076pub struct DocsAgentsCommand {
1078 #[argh(positional)]
1080 pub headings: Vec<String>,
1081 #[argh(switch)]
1083 pub no_subheadings: bool,
1084 #[argh(switch)]
1086 pub full: bool,
1087 #[argh(switch)]
1089 pub contract: bool,
1090 #[argh(switch)]
1092 pub with_lines: bool,
1093 #[argh(switch)]
1095 pub refresh: bool,
1096}
1097
1098#[derive(FromArgs, PartialEq, Debug, Clone)]
1099#[argh(subcommand, name = "check-md")]
1100pub struct DocsCheckMdCommand {
1102 #[argh(positional)]
1104 pub file: String,
1105 #[argh(option, default = "String::from(\"calcit.cirru\")")]
1107 pub snapshot: String,
1108 #[argh(option, long = "entry")]
1110 pub legacy_entry: Option<String>,
1111 #[argh(option)]
1113 pub dep: Vec<String>,
1114 #[argh(switch)]
1116 pub quiet: bool,
1117 #[argh(switch, long = "failures-only")]
1119 pub failures_only: bool,
1120}
1121
1122#[derive(FromArgs, PartialEq, Debug, Clone)]
1123#[argh(subcommand, name = "format-md")]
1124pub struct DocsFormatMdCommand {
1126 #[argh(positional)]
1128 pub file: String,
1129 #[argh(switch)]
1131 pub check: bool,
1132}
1133
1134#[derive(FromArgs, PartialEq, Debug, Clone)]
1139#[argh(subcommand, name = "cirru")]
1140pub struct CirruCommand {
1142 #[argh(subcommand)]
1143 pub subcommand: CirruSubcommand,
1144}
1145
1146#[derive(FromArgs, PartialEq, Debug, Clone)]
1147#[argh(subcommand)]
1148pub enum CirruSubcommand {
1149 Parse(CirruParseCommand),
1151 Format(CirruFormatCommand),
1153 ParseEdn(CirruParseEdnCommand),
1155}
1156
1157#[derive(FromArgs, PartialEq, Debug, Clone)]
1158#[argh(subcommand, name = "parse")]
1159pub struct CirruParseCommand {
1161 #[argh(positional)]
1163 pub code: String,
1164 #[argh(switch, short = 'e', long = "expr-one")]
1166 pub expr_one_liner: bool,
1167 #[argh(switch, long = "validate")]
1169 pub validate: bool,
1170}
1171
1172#[derive(FromArgs, PartialEq, Debug, Clone)]
1173#[argh(subcommand, name = "format")]
1174pub struct CirruFormatCommand {
1176 #[argh(positional)]
1178 pub json: String,
1179}
1180
1181#[derive(FromArgs, PartialEq, Debug, Clone)]
1182#[argh(subcommand, name = "parse-edn")]
1183pub struct CirruParseEdnCommand {
1185 #[argh(positional)]
1187 pub edn: Option<String>,
1188 #[argh(option)]
1190 pub file: Option<String>,
1191}
1192
1193#[derive(FromArgs, PartialEq, Debug, Clone)]
1198#[argh(subcommand)]
1199pub enum LibsSubcommand {
1200 Readme(LibsReadmeCommand),
1202 Search(LibsSearchCommand),
1204 ScanMd(LibsScanMdCommand),
1206}
1207
1208#[derive(FromArgs, PartialEq, Debug, Clone)]
1209#[argh(subcommand, name = "readme")]
1210pub struct LibsReadmeCommand {
1212 #[argh(positional)]
1214 pub package: String,
1215 #[argh(positional)]
1217 pub headings: Vec<String>,
1218 #[argh(option)]
1220 pub file: Option<String>,
1221 #[argh(switch)]
1223 pub no_subheadings: bool,
1224 #[argh(switch)]
1226 pub full: bool,
1227 #[argh(switch)]
1229 pub with_lines: bool,
1230}
1231
1232#[derive(FromArgs, PartialEq, Debug, Clone)]
1233#[argh(subcommand, name = "search")]
1234pub struct LibsSearchCommand {
1236 #[argh(positional)]
1238 pub keyword: String,
1239}
1240
1241#[derive(FromArgs, PartialEq, Debug, Clone)]
1242#[argh(subcommand, name = "scan-md")]
1243pub struct LibsScanMdCommand {
1245 #[argh(positional, default = "String::new()")]
1247 pub module: String,
1248}
1249
1250#[derive(PartialEq, Eq, Debug, Clone, Copy, Default)]
1256pub enum SyntaxInputFormat {
1257 #[default]
1259 Auto,
1260 Cirru,
1262 JsonAst,
1264}
1265
1266impl std::fmt::Display for SyntaxInputFormat {
1267 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1268 f.write_str(match self {
1269 Self::Auto => "auto",
1270 Self::Cirru => "cirru",
1271 Self::JsonAst => "json-ast",
1272 })
1273 }
1274}
1275
1276impl std::str::FromStr for SyntaxInputFormat {
1277 type Err = String;
1278
1279 fn from_str(raw: &str) -> Result<Self, Self::Err> {
1280 match raw {
1281 "auto" => Ok(Self::Auto),
1282 "cirru" | "cirru-edn" => Ok(Self::Cirru),
1283 "json-ast" | "json" => Ok(Self::JsonAst),
1284 other => Err(format!(
1285 "Unknown syntax input format `{other}`. Expected `cirru`, `json-ast`, or compatibility mode `auto`."
1286 )),
1287 }
1288 }
1289}
1290
1291#[derive(FromArgs, PartialEq, Debug, Clone)]
1292#[argh(subcommand, name = "edit")]
1293pub struct EditCommand {
1295 #[argh(subcommand)]
1296 pub subcommand: EditSubcommand,
1297}
1298
1299#[derive(FromArgs, PartialEq, Debug, Clone)]
1300#[argh(subcommand)]
1301pub enum EditSubcommand {
1302 Format(EditFormatCommand),
1304 Merge(EditMergeCommand),
1306 Transaction(EditTransactionCommand),
1308 Scaffold(EditScaffoldCommand),
1310 Def(EditDefCommand),
1312 MvDef(EditMvDefCommand),
1314 RmDef(EditRmDefCommand),
1316 Meta(EditMetaCommand),
1318 Schema(EditSchemaCommand),
1320 Ffi(EditFfiCommand),
1322 AddTest(EditAddTestCommand),
1324 AddNs(EditAddNsCommand),
1326 RmNs(EditRmNsCommand),
1328 Ns(EditNsCommand),
1330 Imports(EditImportsCommand),
1332 AddImport(EditAddImportCommand),
1334 RmImport(EditRmImportCommand),
1336 Rename(EditRenameCommand),
1338 SplitDef(EditSplitDefCommand),
1340}
1341
1342#[derive(FromArgs, PartialEq, Debug, Clone)]
1343#[argh(subcommand, name = "format")]
1344pub struct EditFormatCommand {
1346 #[argh(option, long = "drop-legacy-entry-field")]
1349 pub drop_legacy_entry_fields: Vec<String>,
1350}
1351
1352#[derive(FromArgs, PartialEq, Debug, Clone)]
1353#[argh(subcommand, name = "merge")]
1354pub struct EditMergeCommand {
1357 #[argh(option)]
1359 pub base: String,
1360 #[argh(option)]
1362 pub theirs: String,
1363}
1364
1365#[derive(FromArgs, PartialEq, Debug, Clone)]
1366#[argh(subcommand, name = "transaction")]
1367pub struct EditTransactionCommand {
1369 #[argh(option)]
1371 pub file: Option<String>,
1372 #[argh(option, long = "code")]
1374 pub code: Option<String>,
1375 #[argh(option, long = "expect-revision")]
1377 pub expect_revision: Option<String>,
1378 #[argh(switch, long = "dry-run")]
1380 pub dry_run: bool,
1381 #[argh(option, default = "String::from(\"human\")")]
1383 pub format: String,
1384}
1385
1386#[derive(FromArgs, PartialEq, Debug, Clone)]
1387#[argh(subcommand, name = "scaffold")]
1388pub struct EditScaffoldCommand {
1390 #[argh(option)]
1392 pub file: Option<String>,
1393 #[argh(option, long = "code")]
1395 pub code: Option<String>,
1396 #[argh(option, long = "expect-revision")]
1398 pub expect_revision: Option<String>,
1399 #[argh(switch, long = "dry-run")]
1401 pub dry_run: bool,
1402 #[argh(option, default = "String::from(\"human\")")]
1404 pub format: String,
1405}
1406
1407#[derive(FromArgs, PartialEq, Debug, Clone)]
1410#[argh(subcommand, name = "def")]
1411pub struct EditDefCommand {
1413 #[argh(positional)]
1415 pub target: String,
1416 #[argh(option)]
1418 pub file: Option<String>,
1419 #[argh(option, long = "code")]
1421 pub code: Option<String>,
1422 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1424 pub input_format: SyntaxInputFormat,
1425 #[argh(switch, long = "overwrite")]
1427 pub overwrite: bool,
1428 #[argh(switch, long = "allow-unknown-head")]
1430 pub allow_unknown_head: bool,
1431}
1432
1433#[derive(FromArgs, PartialEq, Debug, Clone)]
1434#[argh(subcommand, name = "mv-def")]
1435pub struct EditMvDefCommand {
1437 #[argh(positional)]
1439 pub source: String,
1440 #[argh(positional)]
1442 pub target: String,
1443}
1444
1445#[derive(FromArgs, PartialEq, Debug, Clone)]
1446#[argh(subcommand, name = "rm-def")]
1447pub struct EditRmDefCommand {
1449 #[argh(positional)]
1451 pub target: String,
1452}
1453
1454#[derive(FromArgs, PartialEq, Debug, Clone)]
1455#[argh(subcommand, name = "meta")]
1456pub struct EditMetaCommand {
1458 #[argh(positional)]
1460 pub target: String,
1461 #[argh(option)]
1463 pub doc: Option<String>,
1464 #[argh(option)]
1466 pub tags: Option<String>,
1467 #[argh(option, long = "add-tag")]
1469 pub add_tags: Vec<String>,
1470 #[argh(option, long = "rm-tag")]
1472 pub rm_tags: Vec<String>,
1473 #[argh(switch, long = "clear-tags")]
1475 pub clear_tags: bool,
1476 #[argh(switch, long = "examples")]
1478 pub examples: bool,
1479 #[argh(switch, long = "add-example")]
1481 pub add_example: bool,
1482 #[argh(option, long = "at")]
1484 pub at: Option<usize>,
1485 #[argh(switch, long = "clear-examples")]
1487 pub clear_examples: bool,
1488 #[argh(option)]
1490 pub file: Option<String>,
1491 #[argh(option, long = "code")]
1493 pub code: Option<String>,
1494 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1496 pub input_format: SyntaxInputFormat,
1497 #[argh(option, long = "rm-test")]
1499 pub rm_tests: Vec<String>,
1500 #[argh(option, long = "expect-revision")]
1502 pub expect_revision: Option<String>,
1503 #[argh(switch, long = "dry-run")]
1505 pub dry_run: bool,
1506 #[argh(option, default = "String::from(\"human\")")]
1508 pub format: String,
1509}
1510
1511#[derive(FromArgs, PartialEq, Debug, Clone)]
1512#[argh(subcommand, name = "schema")]
1513pub struct EditSchemaCommand {
1515 #[argh(positional)]
1517 pub target: String,
1518 #[argh(option)]
1520 pub file: Option<String>,
1521 #[argh(option, long = "code")]
1523 pub code: Option<String>,
1524 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1526 pub input_format: SyntaxInputFormat,
1527 #[argh(switch, long = "clear")]
1529 pub clear: bool,
1530 #[argh(option, long = "add-feature")]
1532 pub add_feature: Option<String>,
1533}
1534
1535#[derive(FromArgs, PartialEq, Debug, Clone)]
1536#[argh(subcommand, name = "ffi")]
1537pub struct EditFfiCommand {
1539 #[argh(positional)]
1541 pub target: String,
1542 #[argh(option)]
1544 pub file: Option<String>,
1545 #[argh(option, long = "code")]
1547 pub code: Option<String>,
1548 #[argh(switch, long = "clear")]
1550 pub clear: bool,
1551}
1552
1553#[derive(FromArgs, PartialEq, Debug, Clone)]
1554#[argh(subcommand, name = "add-test")]
1555pub struct EditAddTestCommand {
1557 #[argh(positional)]
1559 pub target: String,
1560 #[argh(positional)]
1562 pub name: String,
1563 #[argh(option)]
1565 pub tags: Option<String>,
1566 #[argh(option)]
1568 pub file: Option<String>,
1569 #[argh(option, long = "code")]
1571 pub code: Option<String>,
1572 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1574 pub input_format: SyntaxInputFormat,
1575 #[argh(switch, long = "overwrite")]
1577 pub overwrite: bool,
1578}
1579
1580#[derive(FromArgs, PartialEq, Debug, Clone)]
1583#[argh(subcommand, name = "add-ns")]
1584pub struct EditAddNsCommand {
1586 #[argh(positional)]
1588 pub namespace: String,
1589 #[argh(option)]
1591 pub file: Option<String>,
1592 #[argh(option, long = "code")]
1594 pub code: Option<String>,
1595 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1597 pub input_format: SyntaxInputFormat,
1598}
1599
1600#[derive(FromArgs, PartialEq, Debug, Clone)]
1601#[argh(subcommand, name = "rm-ns")]
1602pub struct EditRmNsCommand {
1604 #[argh(positional)]
1606 pub namespace: String,
1607}
1608
1609#[derive(FromArgs, PartialEq, Debug, Clone)]
1610#[argh(subcommand, name = "ns")]
1611pub struct EditNsCommand {
1614 #[argh(positional)]
1616 pub namespace: String,
1617 #[argh(option)]
1619 pub file: Option<String>,
1620 #[argh(option, long = "code")]
1622 pub code: Option<String>,
1623 #[argh(option, long = "expect-revision")]
1625 pub expect_revision: Option<String>,
1626 #[argh(switch, long = "dry-run")]
1628 pub dry_run: bool,
1629 #[argh(switch, long = "allow-remove")]
1631 pub allow_remove: bool,
1632 #[argh(switch, long = "allow-unknown-head")]
1634 pub allow_unknown_head: bool,
1635 #[argh(option, default = "String::from(\"human\")")]
1637 pub format: String,
1638}
1639
1640#[derive(FromArgs, PartialEq, Debug, Clone)]
1641#[argh(subcommand, name = "imports")]
1642pub struct EditImportsCommand {
1644 #[argh(positional)]
1646 pub namespace: String,
1647 #[argh(option)]
1649 pub file: Option<String>,
1650 #[argh(option, long = "code")]
1652 pub code: Option<String>,
1653 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1655 pub input_format: SyntaxInputFormat,
1656}
1657
1658#[derive(FromArgs, PartialEq, Debug, Clone)]
1659#[argh(subcommand, name = "add-import")]
1660pub struct EditAddImportCommand {
1662 #[argh(positional)]
1664 pub namespace: String,
1665 #[argh(option)]
1667 pub file: Option<String>,
1668 #[argh(option, long = "code")]
1670 pub code: Option<String>,
1671 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1673 pub input_format: SyntaxInputFormat,
1674 #[argh(switch, long = "overwrite")]
1676 pub overwrite: bool,
1677}
1678
1679#[derive(FromArgs, PartialEq, Debug, Clone)]
1680#[argh(subcommand, name = "rm-import")]
1681pub struct EditRmImportCommand {
1683 #[argh(positional)]
1685 pub namespace: String,
1686 #[argh(positional)]
1688 pub source_ns: String,
1689}
1690
1691#[derive(FromArgs, PartialEq, Debug, Clone)]
1696#[argh(subcommand, name = "tree")]
1697pub struct TreeCommand {
1699 #[argh(subcommand)]
1700 pub subcommand: TreeSubcommand,
1701}
1702
1703#[derive(FromArgs, PartialEq, Debug, Clone)]
1704#[argh(subcommand)]
1705pub enum TreeSubcommand {
1706 Show(TreeShowCommand),
1707 Replace(TreeReplaceCommand),
1708 ReplaceLeaf(TreeReplaceLeafCommand),
1709 Delete(TreeDeleteCommand),
1710 Insert(TreeInsertCommand),
1711 Swap(TreeSwapCommand),
1712 Unwrap(TreeUnwrapCommand),
1713 Raise(TreeRaiseCommand),
1714 Wrap(TreeWrapCommand),
1715 SearchReplace(TreeSearchReplaceCommand),
1716 Rewrite(TreeStructuralCommand),
1717}
1718
1719#[derive(FromArgs, PartialEq, Debug, Clone)]
1721#[argh(subcommand, name = "show")]
1722pub struct TreeShowCommand {
1723 #[argh(positional)]
1725 pub target: String,
1726 #[argh(option)]
1728 pub path: Option<String>,
1729 #[argh(option, default = "2")]
1731 pub depth: usize,
1732 #[argh(option, default = "String::from(\"human\")")]
1734 pub format: String,
1735 #[argh(option, default = "56")]
1737 pub chunk_target_nodes: usize,
1738 #[argh(option, default = "68")]
1740 pub chunk_max_nodes: usize,
1741 #[argh(option, default = "88")]
1743 pub chunk_trigger_nodes: usize,
1744 #[argh(option, default = "1")]
1746 pub chunk_expand_depth: usize,
1747 #[argh(switch)]
1749 pub raw: bool,
1750 #[argh(switch)]
1752 pub path_annotations: bool,
1753}
1754
1755#[derive(FromArgs, PartialEq, Debug, Clone)]
1757#[argh(subcommand, name = "rename")]
1758pub struct EditRenameCommand {
1759 #[argh(positional)]
1761 pub source: String,
1762 #[argh(positional)]
1764 pub new_name: String,
1765}
1766
1767#[derive(FromArgs, PartialEq, Debug, Clone)]
1769#[argh(subcommand, name = "split-def")]
1770pub struct EditSplitDefCommand {
1771 #[argh(positional)]
1773 pub target: String,
1774 #[argh(option, long = "path")]
1776 pub path: String,
1777 #[argh(option, long = "name")]
1779 pub new_name: String,
1780}
1781
1782#[derive(FromArgs, PartialEq, Debug, Clone)]
1784#[argh(subcommand, name = "rewrite")]
1785pub struct TreeStructuralCommand {
1786 #[argh(positional)]
1788 pub target: String,
1789 #[argh(option)]
1791 pub path: String,
1792 #[argh(option)]
1794 pub file: Option<String>,
1795 #[argh(option, long = "code")]
1797 pub code: Option<String>,
1798 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1800 pub input_format: SyntaxInputFormat,
1801 #[argh(option, long = "with")]
1803 pub with: Vec<String>,
1804 #[argh(option, default = "2")]
1806 pub depth: usize,
1807}
1808
1809#[derive(FromArgs, PartialEq, Debug, Clone)]
1811#[argh(subcommand, name = "search-replace")]
1812pub struct TreeSearchReplaceCommand {
1813 #[argh(positional)]
1815 pub target: String,
1816 #[argh(option, long = "pattern")]
1818 pub pattern: String,
1819 #[argh(switch, long = "regex")]
1821 pub regex: bool,
1822 #[argh(option)]
1824 pub file: Option<String>,
1825 #[argh(option, long = "code")]
1827 pub code: Option<String>,
1828 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1830 pub input_format: SyntaxInputFormat,
1831 #[argh(option, default = "2")]
1833 pub depth: usize,
1834 #[argh(option, long = "pick")]
1836 pub pick: Option<usize>,
1837 #[argh(option, long = "selector")]
1840 pub selector: Option<String>,
1841}
1842
1843#[derive(FromArgs, PartialEq, Debug, Clone)]
1845#[argh(subcommand, name = "replace")]
1846pub struct TreeReplaceCommand {
1847 #[argh(positional)]
1849 pub target: String,
1850 #[argh(option)]
1852 pub path: String,
1853 #[argh(option)]
1855 pub file: Option<String>,
1856 #[argh(option, long = "code")]
1858 pub code: Option<String>,
1859 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1861 pub input_format: SyntaxInputFormat,
1862 #[argh(option)]
1864 pub expect: Option<String>,
1865 #[argh(option, default = "2")]
1867 pub depth: usize,
1868}
1869
1870#[derive(FromArgs, PartialEq, Debug, Clone)]
1872#[argh(subcommand, name = "replace-leaf")]
1873pub struct TreeReplaceLeafCommand {
1874 #[argh(positional)]
1876 pub target: String,
1877 #[argh(option, long = "pattern")]
1879 pub pattern: String,
1880 #[argh(switch, long = "regex")]
1882 pub regex: bool,
1883 #[argh(option)]
1885 pub file: Option<String>,
1886 #[argh(option, long = "code")]
1888 pub code: Option<String>,
1889 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1891 pub input_format: SyntaxInputFormat,
1892 #[argh(option, default = "2")]
1894 pub depth: usize,
1895}
1896
1897#[derive(FromArgs, PartialEq, Debug, Clone)]
1899#[argh(subcommand, name = "delete")]
1900pub struct TreeDeleteCommand {
1901 #[argh(positional)]
1903 pub target: String,
1904 #[argh(option)]
1906 pub path: String,
1907 #[argh(option)]
1909 pub expect: Option<String>,
1910 #[argh(option, default = "2")]
1912 pub depth: usize,
1913}
1914
1915#[derive(FromArgs, PartialEq, Debug, Clone)]
1917#[argh(subcommand, name = "insert")]
1918pub struct TreeInsertCommand {
1919 #[argh(positional)]
1921 pub target: String,
1922 #[argh(option)]
1924 pub path: String,
1925 #[argh(option)]
1927 pub at: String,
1928 #[argh(option)]
1930 pub file: Option<String>,
1931 #[argh(option, long = "code")]
1933 pub code: Option<String>,
1934 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
1936 pub input_format: SyntaxInputFormat,
1937 #[argh(option)]
1939 pub expect: Option<String>,
1940 #[argh(option, default = "2")]
1942 pub depth: usize,
1943}
1944
1945#[derive(FromArgs, PartialEq, Debug, Clone)]
1947#[argh(subcommand, name = "swap")]
1948pub struct TreeSwapCommand {
1949 #[argh(positional)]
1951 pub target: String,
1952 #[argh(option)]
1954 pub path: String,
1955 #[argh(option, long = "with")]
1957 pub with: String,
1958 #[argh(option, default = "2")]
1960 pub depth: usize,
1961}
1962
1963#[derive(FromArgs, PartialEq, Debug, Clone)]
1965#[argh(subcommand, name = "unwrap")]
1966pub struct TreeUnwrapCommand {
1967 #[argh(positional)]
1969 pub target: String,
1970 #[argh(option)]
1972 pub path: String,
1973 #[argh(option, default = "2")]
1975 pub depth: usize,
1976}
1977
1978#[derive(FromArgs, PartialEq, Debug, Clone)]
1980#[argh(subcommand, name = "raise")]
1981pub struct TreeRaiseCommand {
1982 #[argh(positional)]
1984 pub target: String,
1985 #[argh(option)]
1987 pub path: String,
1988 #[argh(option, default = "2")]
1990 pub depth: usize,
1991}
1992
1993#[derive(FromArgs, PartialEq, Debug, Clone)]
1995#[argh(subcommand, name = "wrap")]
1996pub struct TreeWrapCommand {
1997 #[argh(positional)]
1999 pub target: String,
2000 #[argh(option)]
2002 pub path: String,
2003 #[argh(option, long = "code")]
2005 pub code: Option<String>,
2006 #[argh(option)]
2008 pub file: Option<String>,
2009 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
2011 pub input_format: SyntaxInputFormat,
2012 #[argh(option, default = "2")]
2014 pub depth: usize,
2015}
2016
2017#[derive(FromArgs, PartialEq, Debug, Clone)]
2022#[argh(subcommand, name = "cursor")]
2023pub struct CursorCommand {
2025 #[argh(subcommand)]
2026 pub subcommand: CursorSubcommand,
2027}
2028
2029#[derive(FromArgs, PartialEq, Debug, Clone)]
2030#[argh(subcommand)]
2031pub enum CursorSubcommand {
2032 Set(CursorSetCommand),
2033 Show(CursorShowCommand),
2034 Clear(CursorClearCommand),
2035 Move(CursorMoveCommand),
2036 Apply(CursorApplyCommand),
2037}
2038
2039#[derive(FromArgs, PartialEq, Debug, Clone)]
2040#[argh(subcommand, name = "set")]
2041pub struct CursorSetCommand {
2043 #[argh(positional)]
2045 pub target: String,
2046 #[argh(option)]
2048 pub path: String,
2049}
2050
2051#[derive(FromArgs, PartialEq, Debug, Clone)]
2052#[argh(subcommand, name = "show")]
2053pub struct CursorShowCommand {
2055 #[argh(option, default = "String::from(\"human\")")]
2057 pub format: String,
2058 #[argh(option, default = "String::from(\"focus\")")]
2060 pub view: String,
2061}
2062
2063#[derive(FromArgs, PartialEq, Debug, Clone)]
2064#[argh(subcommand, name = "clear")]
2065pub struct CursorClearCommand {}
2067
2068#[derive(FromArgs, PartialEq, Debug, Clone)]
2069#[argh(subcommand, name = "move")]
2070pub struct CursorMoveCommand {
2072 #[argh(positional)]
2074 pub direction: String,
2075 #[argh(positional)]
2077 pub index: Option<usize>,
2078 #[argh(switch)]
2080 pub last: bool,
2081 #[argh(option)]
2083 pub count: Option<usize>,
2084}
2085
2086#[derive(FromArgs, PartialEq, Debug, Clone)]
2087#[argh(subcommand, name = "apply")]
2088pub struct CursorApplyCommand {
2090 #[argh(positional)]
2092 pub operation: String,
2093 #[argh(option)]
2095 pub file: Option<String>,
2096 #[argh(option, long = "code")]
2098 pub code: Option<String>,
2099 #[argh(option, long = "input-format", default = "SyntaxInputFormat::Auto")]
2101 pub input_format: SyntaxInputFormat,
2102 #[argh(option, default = "2")]
2104 pub depth: usize,
2105 #[argh(option)]
2107 pub at: Option<String>,
2108}
2109
2110#[derive(FromArgs, PartialEq, Debug, Clone)]
2116#[argh(subcommand, name = "config")]
2117pub struct ConfigCommand {
2118 #[argh(subcommand)]
2119 pub subcommand: ConfigSubcommand,
2120}
2121
2122#[derive(FromArgs, PartialEq, Debug, Clone)]
2123#[argh(subcommand)]
2124pub enum ConfigSubcommand {
2125 Show(ConfigShowCommand),
2127 Modules(ConfigModulesCommand),
2129 TypeSlots(ConfigTypeSlotsCommand),
2131 Set(ConfigSetCommand),
2133 Unset(ConfigUnsetCommand),
2135 AddEntry(ConfigAddEntryCommand),
2137 AddModule(ConfigAddModuleCommand),
2139 RmModule(ConfigRmModuleCommand),
2141 SetTypeSlot(ConfigSetTypeSlotCommand),
2143 RmTypeSlot(ConfigRmTypeSlotCommand),
2145}
2146
2147#[derive(FromArgs, PartialEq, Debug, Clone)]
2148#[argh(subcommand, name = "show")]
2149pub struct ConfigShowCommand {
2151 #[argh(option)]
2153 pub entry: Option<String>,
2154 #[argh(option, default = "String::from(\"human\")")]
2156 pub format: String,
2157}
2158
2159#[derive(FromArgs, PartialEq, Debug, Clone)]
2160#[argh(subcommand, name = "modules")]
2161pub struct ConfigModulesCommand {
2163 #[argh(option)]
2165 pub entry: Option<String>,
2166 #[argh(option, default = "String::from(\"human\")")]
2168 pub format: String,
2169}
2170
2171#[derive(FromArgs, PartialEq, Debug, Clone)]
2172#[argh(subcommand, name = "type-slots")]
2173pub struct ConfigTypeSlotsCommand {
2175 #[argh(option)]
2177 pub entry: Option<String>,
2178 #[argh(option, default = "String::from(\"human\")")]
2180 pub format: String,
2181}
2182
2183#[derive(FromArgs, PartialEq, Debug, Clone)]
2184#[argh(subcommand, name = "set")]
2185pub struct ConfigSetCommand {
2187 #[argh(option)]
2189 pub entry: Option<String>,
2190 #[argh(positional)]
2192 pub key: String,
2193 #[argh(positional)]
2195 pub value: String,
2196}
2197
2198#[derive(FromArgs, PartialEq, Debug, Clone)]
2199#[argh(subcommand, name = "unset")]
2200pub struct ConfigUnsetCommand {
2202 #[argh(option)]
2204 pub entry: Option<String>,
2205 #[argh(positional)]
2207 pub key: String,
2208}
2209
2210#[derive(FromArgs, PartialEq, Debug, Clone)]
2211#[argh(subcommand, name = "add-entry")]
2212pub struct ConfigAddEntryCommand {
2214 #[argh(positional)]
2216 pub name: String,
2217 #[argh(option)]
2219 pub from: Option<String>,
2220 #[argh(option)]
2222 pub mode: Option<String>,
2223 #[argh(option)]
2225 pub target: Option<String>,
2226 #[argh(option)]
2228 pub init_fn: Option<String>,
2229 #[argh(option)]
2231 pub reload_fn: Option<String>,
2232 #[argh(option)]
2234 pub description: Option<String>,
2235}
2236
2237#[derive(FromArgs, PartialEq, Debug, Clone)]
2238#[argh(subcommand, name = "add-module")]
2239pub struct ConfigAddModuleCommand {
2241 #[argh(option)]
2243 pub entry: Option<String>,
2244 #[argh(positional)]
2246 pub module_path: String,
2247}
2248
2249#[derive(FromArgs, PartialEq, Debug, Clone)]
2250#[argh(subcommand, name = "rm-module")]
2251pub struct ConfigRmModuleCommand {
2253 #[argh(option)]
2255 pub entry: Option<String>,
2256 #[argh(positional)]
2258 pub module_path: String,
2259}
2260
2261#[derive(FromArgs, PartialEq, Debug, Clone)]
2262#[argh(subcommand, name = "set-type-slot")]
2263pub struct ConfigSetTypeSlotCommand {
2265 #[argh(option)]
2267 pub entry: Option<String>,
2268 #[argh(positional)]
2270 pub slot: String,
2271 #[argh(positional)]
2273 pub type_path: String,
2274}
2275
2276#[derive(FromArgs, PartialEq, Debug, Clone)]
2277#[argh(subcommand, name = "rm-type-slot")]
2278pub struct ConfigRmTypeSlotCommand {
2280 #[argh(option)]
2282 pub entry: Option<String>,
2283 #[argh(positional)]
2285 pub slot: String,
2286}
2287
2288#[cfg(test)]
2289mod wasm_command_tests {
2290 use super::*;
2291
2292 #[test]
2293 fn parses_config_unset_target() {
2294 let parsed = ToplevelCalcit::from_args(&["calcit"], &["config", "unset", "target"]).expect("parse config unset");
2295 let Some(CalcitCommand::Config(cmd)) = parsed.subcommand else {
2296 panic!("expected config subcommand");
2297 };
2298 let ConfigSubcommand::Unset(opts) = cmd.subcommand else {
2299 panic!("expected config unset subcommand");
2300 };
2301 assert_eq!(opts.entry, None);
2302 assert_eq!(opts.key, "target");
2303
2304 let named = ToplevelCalcit::from_args(&["calcit"], &["config", "unset", "--entry", "server", "target"]).expect("parse named unset");
2305 let Some(CalcitCommand::Config(cmd)) = named.subcommand else {
2306 panic!("expected config subcommand");
2307 };
2308 let ConfigSubcommand::Unset(opts) = cmd.subcommand else {
2309 panic!("expected config unset subcommand");
2310 };
2311 assert_eq!(opts.entry.as_deref(), Some("server"));
2312 }
2313
2314 #[test]
2315 fn parses_public_wasm_commands_with_distinct_targets() {
2316 let wasm = ToplevelCalcit::from_args(&["calcit"], &["wasm", "app.cirru", "--emit-path", "target/core", "--check-only"])
2317 .expect("parse calcit wasm");
2318 let Some(CalcitCommand::EmitWasm(options)) = wasm.subcommand else {
2319 panic!("expected wasm subcommand");
2320 };
2321 assert_eq!(options.input.as_deref(), Some("app.cirru"));
2322 assert_eq!(options.emit_path.as_deref(), Some("target/core"));
2323 assert_eq!(options.boundary, "native");
2324 assert!(options.check_only);
2325
2326 let component =
2327 ToplevelCalcit::from_args(&["calcit"], &["wasm", "app.cirru", "--boundary", "component"]).expect("parse component boundary");
2328 let Some(CalcitCommand::EmitWasm(options)) = component.subcommand else {
2329 panic!("expected wasm subcommand");
2330 };
2331 assert_eq!(options.boundary, "component");
2332
2333 let wasi =
2334 ToplevelCalcit::from_args(&["calcit"], &["wasi", "command.cirru", "--init-fn", "app.main/main!"]).expect("parse calcit wasi");
2335 let Some(CalcitCommand::EmitWasi(options)) = wasi.subcommand else {
2336 panic!("expected wasi subcommand");
2337 };
2338 assert_eq!(options.input.as_deref(), Some("command.cirru"));
2339 assert_eq!(options.init_fn.as_deref(), Some("app.main/main!"));
2340 assert_eq!(options.boundary, "component");
2341 assert_eq!(options.world, "command");
2342 assert!(!options.check_only);
2343
2344 let http = ToplevelCalcit::from_args(&["calcit"], &["wasi", "http.cirru", "--world", "http"]).expect("parse WASI HTTP proxy world");
2345 let Some(CalcitCommand::EmitWasi(options)) = http.subcommand else {
2346 panic!("expected wasi subcommand");
2347 };
2348 assert_eq!(options.boundary, "component");
2349 assert_eq!(options.world, "http");
2350
2351 let preview1 = ToplevelCalcit::from_args(&["calcit"], &["wasi", "command.cirru", "--boundary", "native"])
2352 .expect("parse WASI Preview 1 command boundary");
2353 let Some(CalcitCommand::EmitWasi(options)) = preview1.subcommand else {
2354 panic!("expected wasi subcommand");
2355 };
2356 assert_eq!(options.boundary, "native");
2357 }
2358
2359 #[test]
2360 fn parses_keep_going_check_report_options() {
2361 let command = ToplevelCalcit::from_args(&["calcit"], &["app.cirru", "--check-only", "--keep-going", "--format", "edn"])
2362 .expect("parse keep-going strict check");
2363 assert_eq!(command.input, "app.cirru");
2364 assert!(command.check_only);
2365 assert!(command.keep_going);
2366 assert_eq!(command.format, "edn");
2367 }
2368
2369 #[test]
2370 fn parses_incremental_check_only_option() {
2371 let command =
2372 ToplevelCalcit::from_args(&["calcit"], &["app.cirru", "--check-only", "--incremental"]).expect("parse incremental strict check");
2373 assert_eq!(command.input, "app.cirru");
2374 assert!(command.check_only);
2375 assert!(command.incremental);
2376 assert!(!command.keep_going);
2377 }
2378
2379 #[test]
2380 fn parses_all_defs_check_only_option() {
2381 let command = ToplevelCalcit::from_args(&["calcit"], &["app.cirru", "--check-only", "--all-defs", "--format", "edn"])
2382 .expect("parse all-definitions strict check");
2383 assert!(command.check_only);
2384 assert!(command.all_defs);
2385 assert!(!command.summary_only);
2386 assert_eq!(command.format, "edn");
2387 }
2388
2389 #[test]
2390 fn parses_all_defs_summary_only_check_only_option() {
2391 let command = ToplevelCalcit::from_args(
2392 &["calcit"],
2393 &["app.cirru", "--check-only", "--all-defs", "--summary-only", "--format", "edn"],
2394 )
2395 .expect("parse all-definitions summary-only strict check");
2396 assert!(command.check_only);
2397 assert!(command.all_defs);
2398 assert!(command.summary_only);
2399 assert_eq!(command.format, "edn");
2400 }
2401}