-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcommand_surface.rs
More file actions
170 lines (153 loc) · 5.08 KB
/
Copy pathcommand_surface.rs
File metadata and controls
170 lines (153 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use std::fmt::Write;
use crate::{cli_schema, services};
use services::style::{banner_with_gradient, command_name, heading};
const SCE_BANNER_LINES: &[&str] = &[
r" ______ ______ ________ ",
r".' ____ \ .' ___ ||_ __ | ",
r"| (___ \_|/ .' \_| | |_ \_| ",
r" _.____`. | | | _| _ ",
r"| \____) |\ `.___.'\ _| |__/ | ",
r" \______.' `.____ .'|________| ",
];
const HELP_COMMAND_NAME: &str = "help";
const HELP_COMMAND_PURPOSE: &str = "Show help for the current CLI surface";
pub fn is_known_command(name: &str) -> bool {
name == HELP_COMMAND_NAME
|| cli_schema::TOP_LEVEL_COMMANDS
.iter()
.any(|command| command.name == name)
}
enum HelpSectionBodyLine {
Text(&'static str),
Command {
cmd: &'static str,
suffix: &'static str,
},
}
struct HelpSection {
title: &'static str,
body: &'static [HelpSectionBodyLine],
}
const HELP_SECTIONS: &[HelpSection] = &[
HelpSection {
title: "Usage:",
body: &[HelpSectionBodyLine::Text(" sce [command]")],
},
HelpSection {
title: "Config Usage:",
body: &[HelpSectionBodyLine::Command {
cmd: " sce config",
suffix: " <show|validate> [--format <text|json>] [options]",
}],
},
HelpSection {
title: "Setup Usage:",
body: &[HelpSectionBodyLine::Command {
cmd: " sce setup",
suffix:
" [--opencode|--claude|--pi|--codex|--all] [--non-interactive] [--hooks] [--repo <path>] [--bootstrap-context]",
}],
},
HelpSection {
title: "Doctor Usage:",
body: &[HelpSectionBodyLine::Command {
cmd: " sce doctor",
suffix: " [--fix] [--format <text|json>]",
}],
},
HelpSection {
title: "Version Usage:",
body: &[HelpSectionBodyLine::Command {
cmd: " sce version",
suffix: " [--format <text|json>]",
}],
},
HelpSection {
title: "Completion Usage:",
body: &[HelpSectionBodyLine::Command {
cmd: " sce completion",
suffix: " --shell <bash|zsh|fish>",
}],
},
HelpSection {
title: "Output format contract:",
body: &[HelpSectionBodyLine::Text(
" Supported commands accept --format <text|json>",
)],
},
HelpSection {
title: "Examples:",
body: &[
HelpSectionBodyLine::Text(" sce config"),
HelpSectionBodyLine::Text(" sce config show --format json"),
HelpSectionBodyLine::Text(" sce setup"),
HelpSectionBodyLine::Text(" sce setup --opencode --non-interactive --hooks"),
HelpSectionBodyLine::Text(" sce setup --hooks --repo ../demo-repo"),
HelpSectionBodyLine::Text(" sce setup --bootstrap-context"),
HelpSectionBodyLine::Text(" sce setup --claude --non-interactive --workflow brownfield"),
HelpSectionBodyLine::Text(" sce doctor --format json"),
HelpSectionBodyLine::Text(" sce doctor --fix"),
HelpSectionBodyLine::Text(" sce version --format json"),
],
},
];
fn commands_section() -> String {
let mut out = String::new();
writeln!(out, "{}", heading("Commands")).expect("writing to String should not fail");
writeln!(
out,
" {:<10} {}",
command_name(HELP_COMMAND_NAME),
HELP_COMMAND_PURPOSE
)
.expect("writing to String should never fail");
for command in cli_schema::TOP_LEVEL_COMMANDS {
if command.show_in_top_level_help {
writeln!(
out,
" {:<10} {}",
command_name(command.name),
command.purpose
)
.expect("writing to String should never fail");
}
}
out
}
fn push_blank_line(out: &mut String) {
out.push('\n');
}
fn push_section(out: &mut String, section: &str) {
out.push_str(section);
}
pub fn help_text() -> String {
let mut output = String::new();
push_section(&mut output, &banner_with_gradient(SCE_BANNER_LINES));
push_blank_line(&mut output);
push_blank_line(&mut output);
push_section(
&mut output,
&heading("sce - Shared Context Engineering CLI"),
);
push_blank_line(&mut output);
push_blank_line(&mut output);
for section in HELP_SECTIONS {
push_section(&mut output, &heading(section.title));
push_blank_line(&mut output);
for line in section.body {
match line {
HelpSectionBodyLine::Text(text) => {
push_section(&mut output, text);
push_blank_line(&mut output);
}
HelpSectionBodyLine::Command { cmd, suffix } => {
writeln!(output, "{}{}", command_name(cmd), suffix)
.expect("writing to String should never fail");
}
}
}
push_blank_line(&mut output);
}
writeln!(output, "{}", commands_section()).expect("writing to String should not fail");
output
}