- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLine.cs
More file actions
Latest commit
118 lines (103 loc) · 3.89 KB
/
Copy pathCommandLine.cs
File metadata and controls
118 lines (103 loc) · 3.89 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
usingSystem.CommandLine;
usingSystem.CommandLine.Parsing;
namespaceptr727.LanguageTags.Create;
internalsealedclassCommandLine
{
privatereadonlyOption<LogEventLevel>_logLevelOption=CreateLogLevelOption();
privatereadonlyOption<string>_logFileOption=CreateLogFileOption();
privatereadonlyOption<bool>_logFileClearOption=CreateLogFileClearOption();
privatereadonlyOption<DirectoryInfo>_codePathOption=CreateCodePathOption();
privatereadonlyOption<bool>_skipDownloadOption=CreateSkipDownloadOption();
privatestaticreadonlyFrozenSet<string>s_cliBypassList=FrozenSet.Create(
StringComparer.OrdinalIgnoreCase,
"--help",
"--version"
);
internalCommandLine(string[]args)
{
Root=CreateRootCommand();
Result=Root.Parse(args);
}
internalRootCommandRoot{get;init;}
internalParseResultResult{get;init;}
internalRootCommandCreateRootCommand()
{
RootCommandrootCommand=new("Download and generate language tag data and code")
{
_logLevelOption,
_logFileOption,
_logFileClearOption,
_codePathOption,
_skipDownloadOption,
};
rootCommand.SetAction(
(parseResult,cancellationToken)=>
{
Programprogram=new(CreateOptions(parseResult),cancellationToken);
returnprogram.ExecuteAsync();
}
);
returnrootCommand;
}
internalOptionsCreateOptions(ParseResultparseResult)=>
new()
{
LogOptions=newLoggerFactory.Options
{
Level=parseResult.GetValue(_logLevelOption),
File=parseResult.GetValue(_logFileOption)??string.Empty,
FileClear=parseResult.GetValue(_logFileClearOption),
},
CodePath=parseResult.GetValue(_codePathOption)!,
SkipDownload=parseResult.GetValue(_skipDownloadOption),
};
privatestaticOption<bool>CreateLogFileClearOption()=>
new("--logfile-clear","-c")
{
Description="Clear the log file before writing (default: false).",
Recursive=true,
};
privatestaticOption<LogEventLevel>CreateLogLevelOption()=>
new("--loglevel","-l")
{
Description="Set the log level (default: Information).",
DefaultValueFactory= _ =>LogEventLevel.Information,
Recursive=true,
};
privatestaticOption<string>CreateLogFileOption()
{
Option<string>option=new("--logfile","-f")
{
Description="Write logs to the specified file (optional).",
Recursive=true,
};
returnoption.AcceptLegalFileNamesOnly();
}
privatestaticOption<bool>CreateSkipDownloadOption()=>
new("--skip-download","-s")
{
Description=
"Regenerate from the committed LanguageData/ directory without downloading, offline (default: false).",
};
privatestaticOption<DirectoryInfo>CreateCodePathOption()
{
Option<DirectoryInfo>option=new("--codepath","-p")
{
Description="Path to the solution directory.",
Required=true,
};
returnoption.AcceptExistingOnly();
}
internalstaticboolBypassStartup(ParseResultparseResult)=>
parseResult.Errors.Count>0
||parseResult.CommandResult.Children.Any(symbolResult =>
symbolResultisOptionResultoptionResult
&&s_cliBypassList.Contains(optionResult.Option.Name)
);
internalsealedclassOptions
{
internalrequiredLoggerFactory.OptionsLogOptions{get;init;}
internalrequiredDirectoryInfoCodePath{get;init;}
internalboolSkipDownload{get;init;}
}
}