-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelp.ts
More file actions
138 lines (97 loc) · 2.95 KB
/
Copy pathhelp.ts
File metadata and controls
138 lines (97 loc) · 2.95 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
import { VERSION } from "../index.js";
import {
COMMAND_HELP,
findCommandHelp,
type CommandHelp,
} from "./helpTopics.js";
const DIVIDER = "────────────────────────────────────────────";
const DOCS_URL = "https://docs.seamlessauth.com";
function indent(text: string, spaces: number): string {
const pad = " ".repeat(spaces);
return text
.split("\n")
.map((line) => (line.length > 0 ? pad + line : line))
.join("\n");
}
function renderSections(command: CommandHelp, headingIndent: number): string {
return command.sections
.map(
(section) =>
`${indent(section.heading, headingIndent)}\n${indent(
section.body,
headingIndent + 2,
)}`,
)
.join("\n\n");
}
export function printHelp() {
const usage = COMMAND_HELP.flatMap((c) => c.usage)
.concat(["seamless <command> --help", "seamless --help", "seamless --version"])
.map((line) => ` ${line}`)
.join("\n");
const commands = COMMAND_HELP.map((c) => renderSections(c, 2)).join("\n\n");
console.log(`
seamless v${VERSION}
Seamless CLI — scaffold and manage full-stack authentication systems.
${DIVIDER}
USAGE
${usage}
${DIVIDER}
COMMANDS
${commands}
${DIVIDER}
GETTING STARTED
1. seamless init
2. docker compose up
3. Register in the browser with the email you gave init
→ That address is the owner, so it becomes an admin
${DIVIDER}
WHAT YOU GET
• Web application (React starter, or a use-case example like --oauth)
• API server (Express)
• SeamlessAuth server (Docker or local)
• Admin dashboard (Docker or source)
• Docker Compose setup
${DIVIDER}
EXAMPLES
seamless init
→ Interactive setup in current directory
seamless init my-app
→ Create new project in ./my-app
seamless init --oauth my-app
→ Create ./my-app from the OAuth example starter
seamless check
→ Validate your project
${DIVIDER}
DOCS
${DOCS_URL}
`);
}
// Returns false when the command has no help entry, so the caller can fall
// back to the unknown-command path instead of printing an empty topic.
export function printCommandHelp(name: string): boolean {
const command = findCommandHelp(name);
if (!command) return false;
const usage = command.usage.map((line) => ` ${line}`).join("\n");
// The heading only earns its place when a command has more than one section
// (sessions list vs sessions revoke); otherwise it just repeats the usage.
const description =
command.sections.length === 1
? indent(command.sections[0].body, 2)
: renderSections(command, 2);
const examples = command.examples?.length
? `\nEXAMPLES\n\n${command.examples
.map((example) => indent(example, 2))
.join("\n\n")}\n`
: "";
console.log(`
seamless ${command.name} — seamless v${VERSION}
USAGE
${usage}
DESCRIPTION
${description}
${examples}
Docs: ${DOCS_URL}
`);
return true;
}