Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
163 lines (134 loc) · 5.31 KB
/
Copy pathProgram.cs
File metadata and controls
163 lines (134 loc) · 5.31 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
using System.CommandLine;
using Spectre.Console;
using ShellUI.Native.Templates;
using ShellUI.Native.Core.Models;
using ShellUI.Native.CLI.Services;
namespace ShellUI.Native.CLI;
class Program
{
static async Task<int> Main(string[] args)
{
// The loaders draw Unicode dots and Braille.
Console.OutputEncoding = System.Text.Encoding.UTF8;
var rootCommand = new RootCommand("ShellUI Native - CLI-first cross-platform component library")
{
Description = "Add beautiful, accessible components to your MAUI or Avalonia app. Inspired by shadcn/ui."
};
rootCommand.AddCommand(CreateInitCommand());
rootCommand.AddCommand(CreateAddCommand());
rootCommand.AddCommand(CreateListCommand());
rootCommand.AddCommand(CreateRemoveCommand());
rootCommand.AddCommand(CreateUpdateCommand());
return await rootCommand.InvokeAsync(args);
}
static Command CreateInitCommand()
{
var command = new Command("init", "Initialize ShellUI Native in your project");
var forceOption = new Option<bool>("--force", "Reinitialize even if already initialized");
var styleOption = new Option<string>("--style", () => "default", "Choose component style (default, minimal)");
var nonInteractiveOption = new Option<bool>("--yes", "Run in non-interactive mode with default options");
command.AddOption(forceOption);
command.AddOption(styleOption);
command.AddOption(nonInteractiveOption);
command.SetHandler(async (force, style, nonInteractive) =>
{
try
{
LogoLoader.WriteHeader("Setting up your project");
await InitService.InitializeAsync(style, force, nonInteractive);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message.Replace("[", "[[").Replace("]", "]]")}");
}
}, forceOption, styleOption, nonInteractiveOption);
return command;
}
static Command CreateAddCommand()
{
var command = new Command("add", "Add component(s) to your project");
var componentsArg = new Argument<string[]>("components", "Component name(s) to add (space or comma-separated)")
{
Arity = ArgumentArity.OneOrMore
};
command.AddArgument(componentsArg);
var forceOption = new Option<bool>("--force", "Overwrite existing components");
command.AddOption(forceOption);
command.SetHandler(async (components, force) =>
{
try
{
await ComponentInstaller.InstallComponents(components, force);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message.Replace("[", "[[").Replace("]", "]]")}");
}
}, componentsArg, forceOption);
return command;
}
static Command CreateListCommand()
{
var command = new Command("list", "List available components");
var installedOption = new Option<bool>("--installed", "Show only installed components");
var availableOption = new Option<bool>("--available", "Show only available components");
command.AddOption(installedOption);
command.AddOption(availableOption);
command.SetHandler((installed, available) =>
{
try
{
ComponentManager.ListComponents(installed, available);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message.Replace("[", "[[").Replace("]", "]]")}");
}
}, installedOption, availableOption);
return command;
}
static Command CreateRemoveCommand()
{
var command = new Command("remove", "Remove component(s) from your project");
var componentsArg = new Argument<string[]>("components", "Component name(s) to remove")
{
Arity = ArgumentArity.OneOrMore
};
command.AddArgument(componentsArg);
command.SetHandler((components) =>
{
try
{
ComponentManager.RemoveComponents(components);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message.Replace("[", "[[").Replace("]", "]]")}");
}
}, componentsArg);
return command;
}
static Command CreateUpdateCommand()
{
var command = new Command("update", "Update component(s) to latest version");
var componentsArg = new Argument<string[]>("components", "Component name(s) to update (empty = all)")
{
Arity = ArgumentArity.ZeroOrMore
};
command.AddArgument(componentsArg);
var allOption = new Option<bool>("--all", "Update all installed components");
command.AddOption(allOption);
command.SetHandler((components, all) =>
{
try
{
ComponentManager.UpdateComponents(components, all);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message.Replace("[", "[[").Replace("]", "]]")}");
}
}, componentsArg, allOption);
return command;
}
}