workspacer_show/
show_flags.rs

1// ---------------- [ File: workspacer-show/src/show_flags.rs ]
2crate::ix!();
3
4/// Extended ShowFlags with a new `show_items_with_no_data` flag.
5/// If `show_items_with_no_data` is `true`, we'll display placeholders:
6/// - `<no-data-for-crate>` if a crate is empty
7/// - `<no-data-for-file>` if a file grouping is empty (though in the current approach, we never track truly empty files)
8/// - `<no-data>` if the entire final output is empty
9#[derive(Clone,StructOpt,Setters,MutGetters,Getters,Builder,Debug)]
10#[builder(setter(into))]
11#[getset(get="pub",get_mut="pub",set="pub")]
12pub struct ShowFlags {
13    /// Path to the crate (or workspace root) you want to show.
14    #[structopt(long = "path", parse(from_os_str))]
15    path: Option<PathBuf>,
16
17    /// Include private items
18    #[structopt(long = "include-private")]
19    #[builder(default="false")]
20    include_private: bool,
21
22    /// Include doc items
23    #[structopt(long = "include-docs")]
24    #[builder(default="false")]
25    include_docs: bool,
26
27    /// Include test items
28    #[structopt(long = "include-tests")]
29    #[builder(default="false")]
30    include_tests: bool,
31
32    /// Include function bodies
33    #[structopt(long = "include-fn-bodies")]
34    #[builder(default="false")]
35    include_fn_bodies: bool,
36
37    /// Include test function bodies
38    #[structopt(long = "include-test-bodies")]
39    #[builder(default="false")]
40    include_test_bodies: bool,
41
42    /// Show only test items (skips non-test)
43    #[structopt(long = "just-tests")]
44    #[builder(default="false")]
45    just_tests: bool,
46
47    /// Show only free functions (skips impls, structs, etc.)
48    #[structopt(long = "just-fns")]
49    #[builder(default="false")]
50    just_fns: bool,
51
52    /// Show only impl blocks
53    #[structopt(long = "just-impls")]
54    #[builder(default="false")]
55    just_impls: bool,
56
57    /// Show only traits
58    #[structopt(long = "just-traits")]
59    #[builder(default="false")]
60    just_traits: bool,
61
62    /// Show only enums
63    #[structopt(long = "just-enums")]
64    #[builder(default="false")]
65    just_enums: bool,
66
67    /// Show only structs
68    #[structopt(long = "just-structs")]
69    #[builder(default="false")]
70    just_structs: bool,
71
72    /// Show only type aliases
73    #[structopt(long = "just-aliases")]
74    #[builder(default="false")]
75    just_aliases: bool,
76
77    /// Show only ADTs (enums + structs)
78    #[structopt(long = "just-adts")]
79    #[builder(default="false")]
80    just_adts: bool,
81
82    /// Show only macros
83    #[structopt(long = "just-macros")]
84    #[builder(default="false")]
85    just_macros: bool,
86
87    /// Group items by the file in which they were found
88    #[structopt(long = "group-by-file")]
89    #[builder(default="false")]
90    group_by_syntax_kind: bool,
91
92    /// For `crate-tree` subcommand, do NOT merge all crates into one interface
93    /// (the new default). If false, merges them all.
94    #[structopt(long = "merge-crates")]
95    #[builder(default="false")]
96    merge_crates: bool,
97
98    /// If set, we show <no-data-for-crate> or <no-data-for-file> or <no-data>
99    /// even if a crate or file has no data.
100    #[structopt(long = "show-items-with-no-data")]
101    #[builder(default="false")]
102    show_items_with_no_data: bool,
103
104    // New flags:
105    #[structopt(long = "full", conflicts_with_all = &["for_ai", "for_ai_no_tests"])]
106    full: bool,
107
108    #[structopt(long = "for-ai", conflicts_with_all = &["full", "for_ai_no_tests"])]
109    for_ai: bool,
110
111    #[structopt(long = "for-ai-no-tests", conflicts_with_all = &["full", "for_ai"])]
112    for_ai_no_tests: bool,
113}
114
115impl ShowFlags {
116
117    pub fn crate_dependency_consolidation_options(&self) -> ConsolidationOptions {
118        let mut base = ConsolidationOptions::from(self);
119        if *self.for_ai() || *self.for_ai_no_tests() {
120            base = base.with_tests_disabled();
121        }
122        base
123    }
124}
125
126impl From<&ShowFlags> for ConsolidationOptions {
127
128    fn from(opts: &ShowFlags) -> ConsolidationOptions {
129        // Start with a default
130        let mut c = ConsolidationOptions::new();
131
132        if *opts.full() {
133            // "Full works": show absolutely everything
134            // - doc comments
135            // - private items
136            // - test items
137            // - function bodies (in both normal and test code)
138            c = c.with_docs()
139                 .with_private_items()
140                 .with_test_items()
141                 .with_fn_bodies()
142                 .with_fn_bodies_in_tests();
143        }
144        else if *opts.for_ai() {
145            // "For AI" => show the code + bodies, but *no doc comments*, 
146            // and skip test items for dependencies (we'll see how in run_with_crate).
147            // For the main crate, we DO want test items. 
148            //
149            // So here, we do not call `with_docs()`.
150            // We do want private items, function bodies, test bodies:
151            c = c.with_private_items()
152                 .with_test_items()         // so that in the main crate, tests are included
153                 .with_fn_bodies()
154                 .with_fn_bodies_in_tests();
155        }
156        else if *opts.for_ai_no_tests() {
157            // Like for_ai but also excluding *all* test items (even in the main crate)
158            c = c.with_private_items()
159                 // do not do `with_test_items`
160                 .with_fn_bodies();
161            // We do not call `with_docs()`, so doc lines are excluded.
162        }
163        else {
164            // Fallback: interpret the normal flags as before
165            if *opts.include_docs() {
166                c = c.with_docs();
167            }
168            if *opts.include_private() {
169                c = c.with_private_items();
170            }
171            if *opts.include_tests() {
172                c = c.with_test_items();
173            }
174            if *opts.include_fn_bodies() {
175                c = c.with_fn_bodies();
176            }
177            if *opts.include_test_bodies() {
178                c = c.with_fn_bodies_in_tests();
179            }
180            if *opts.just_tests() {
181                c = c.with_only_test_items();
182            }
183        }
184
185        c.validate();
186        c
187    }
188}