Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
184 lines (176 loc) · 8.05 KB
/
Copy pathProgram.cs
File metadata and controls
184 lines (176 loc) · 8.05 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System.CommandLine;
using ShellDocs.CLI.Commands;
using Spectre.Console;
namespace ShellDocs.CLI;
internal class Program
{
private const string Logo = @"
███████╗██╗ ██╗███████╗██╗ ██╗ ██████╗ ██████╗ ██████╗███████╗
██╔════╝██║ ██║██╔════╝██║ ██║ ██╔══██╗██╔═══██╗██╔════╝██╔════╝
███████╗███████║█████╗ ██║ ██║ ██║ ██║██║ ██║██║ ███████╗
╚════██║██╔══██║██╔══╝ ██║ ██║ ██║ ██║██║ ██║██║ ╚════██║
███████║██║ ██║███████╗███████╗███████╗██████╔╝╚██████╔╝╚██████╗███████║
╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═════╝ ╚═════╝ ╚═════╝╚══════╝
";
private static int Main(string[] args)
{
var root = new RootCommand("ShellDocs — the docs framework for .NET.");
root.Subcommands.Add(CreateInitCommand());
root.Subcommands.Add(CreateAddCommand());
root.Subcommands.Add(CreateDevCommand());
root.Subcommands.Add(CreateBuildCommand());
root.Subcommands.Add(CreatePreviewCommand());
return root.Parse(args).Invoke();
}
private static Command CreateInitCommand()
{
var path = new Argument<string?>("path")
{
Description = "Target directory for the new docs project (default: docs/<CwdName>.Docs). Ignored with --attach.",
Arity = ArgumentArity.ZeroOrOne
};
var dir = new Option<string>("--dir")
{
Description = "Working directory (default: current dir). With --attach, the project directory.",
DefaultValueFactory = _ => Directory.GetCurrentDirectory()
};
var attach = new Option<bool>("--attach")
{
Description = "Augment an existing Blazor project in --dir instead of creating a new one. Emits SHELLDOCS_SETUP.md for manual Program.cs / App.razor patching."
};
var yes = new Option<bool>("--yes") { Description = "Non-interactive mode with default options." };
var theme = new Option<string>("--theme")
{
Description = "Colour preset: " + string.Join(", ", ShellDocs.Templates.ScaffoldTemplates.ThemePresets) + ".",
DefaultValueFactory = _ => "graphite"
};
theme.AcceptOnlyFromAmong(ShellDocs.Templates.ScaffoldTemplates.ThemePresets);
var cmd = new Command("init", "Scaffold a new ShellDocs site (default) or attach to an existing Blazor project.")
{
path, dir, attach, yes, theme
};
cmd.SetAction(pr =>
{
AnsiConsole.Markup($"[blue]{Logo}[/]");
AnsiConsole.MarkupLine("[dim] the docs framework for .NET[/]");
AnsiConsole.WriteLine();
return InitCommand.Run(
pr.GetValue(path),
pr.GetValue(dir) ?? Directory.GetCurrentDirectory(),
pr.GetValue(attach),
pr.GetValue(yes),
pr.GetValue(theme) ?? "graphite");
});
return cmd;
}
private static Command CreateAddCommand()
{
var template = new Argument<string>("template") { Description = "Template: component, guide, page." };
var name = new Argument<string>("name") { Description = "Name of the new page (PascalCase for component, kebab-case for guide/page)." };
var dir = new Option<string>("--dir")
{
Description = "Project directory (default: current dir).",
DefaultValueFactory = _ => Directory.GetCurrentDirectory()
};
var force = new Option<bool>("--force") { Description = "Overwrite an existing file with the same name." };
var cmd = new Command("add", "Scaffold a new doc page from a template into content/.") { template, name, dir, force };
cmd.SetAction(pr => AddCommand.Run(
pr.GetValue(template) ?? "",
pr.GetValue(name) ?? "",
pr.GetValue(dir) ?? Directory.GetCurrentDirectory(),
pr.GetValue(force)));
return cmd;
}
private static Command CreateDevCommand()
{
var dir = new Option<string>("--dir")
{
Description = "Project directory (default: current dir).",
DefaultValueFactory = _ => Directory.GetCurrentDirectory()
};
var port = new Option<int>("--port")
{
Description = "Port to bind on.",
DefaultValueFactory = _ => 5000
};
var cmd = new Command("dev", "Start dev server with hot-reload for .razor / .cs / .md changes.")
{
dir, port
};
cmd.SetAction(pr =>
DevCommand.Run(
pr.GetValue(dir) ?? Directory.GetCurrentDirectory(),
pr.GetValue(port)));
return cmd;
}
private static Command CreateBuildCommand()
{
var dir = new Option<string>("--dir")
{
Description = "Project directory (default: current dir).",
DefaultValueFactory = _ => Directory.GetCurrentDirectory()
};
var output = new Option<string>("--output")
{
Description = "Output directory for the static site.",
DefaultValueFactory = _ => "publish"
};
var baseHref = new Option<string?>("--base-href")
{
Description = "Rewrite <base href> in index.html (e.g. \"/my-repo/\" for GH Pages subpaths)."
};
var spaFallback = new Option<bool>("--spa-fallback")
{
Description = "Copy index.html → 404.html so client-side routes survive on GH Pages."
};
var siteUrl = new Option<string?>("--site-url")
{
Description = "Absolute site URL (e.g. \"https://shelldocs.dev\"). Enables sitemap.xml, robots.txt, and og: meta tags."
};
var cmd = new Command("build", "Produce a static site ready for GH Pages / Cloudflare / S3.")
{
dir, output, baseHref, spaFallback, siteUrl
};
cmd.SetAction(pr =>
BuildCommand.Run(
pr.GetValue(dir) ?? Directory.GetCurrentDirectory(),
pr.GetValue(output) ?? "publish",
pr.GetValue(baseHref),
pr.GetValue(spaFallback),
pr.GetValue(siteUrl)));
return cmd;
}
private static Command CreatePreviewCommand()
{
var dir = new Option<string>("--dir")
{
Description = "Project directory (default: current dir).",
DefaultValueFactory = _ => Directory.GetCurrentDirectory()
};
var output = new Option<string>("--output")
{
Description = "The static site to serve, as passed to shelldocs build.",
DefaultValueFactory = _ => "publish"
};
var port = new Option<int>("--port")
{
Description = "Port to bind on.",
DefaultValueFactory = _ => 5050
};
var baseHref = new Option<string?>("--base-href")
{
Description = "Serve under this path (default: the <base href> the build wrote)."
};
var cmd = new Command("preview", "Serve the output of shelldocs build locally, as a static host would.")
{
dir, output, port, baseHref
};
cmd.SetAction(pr =>
PreviewCommand.Run(
pr.GetValue(dir) ?? Directory.GetCurrentDirectory(),
pr.GetValue(output) ?? "publish",
pr.GetValue(port),
pr.GetValue(baseHref)));
return cmd;
}
}