8
8
using PixelGraph . Common . Projects ;
9
9
using Serilog ;
10
10
using System . CommandLine ;
11
- using System . CommandLine . Invocation ;
12
11
using System . Diagnostics ;
13
12
14
13
namespace PixelGraph . CLI . CommandLine ;
@@ -31,38 +30,49 @@ public PublishCommand(
31
30
this . lifetime = lifetime ;
32
31
this . logger = logger ;
33
32
34
- Command = new Command ( "publish" , "Publishes the specified profile." ) {
35
- Handler = CommandHandler . Create < FileInfo , string , DirectoryInfo , FileInfo , bool , int > ( RunAsync ) ,
36
- } ;
37
-
38
- Command . AddOption ( new Option < FileInfo > (
33
+ var optProjectFile = new Option < FileInfo > (
39
34
new [ ] { "-p" , "--project-file" } , ( ) => new FileInfo ( "project.yml" ) ,
40
- "The filename of the project to publish." ) ) ;
35
+ "The filename of the project to publish." ) ;
41
36
42
- Command . AddOption ( new Option < string > (
37
+ var optProfileName = new Option < string > (
43
38
new [ ] { "-n" , "--profile-name" } ,
44
- "The name of the publish-profile within the project to publish." ) ) ;
39
+ "The name of the publish-profile within the project to publish." ) ;
45
40
46
- Command . AddOption ( new Option < DirectoryInfo > (
41
+ var optDestination = new Option < DirectoryInfo > (
47
42
new [ ] { "-o" , "--output" } ,
48
- "The target directory to publish the resource pack to." ) ) ;
43
+ "The target directory to publish the resource pack to." ) ;
49
44
50
- Command . AddOption ( new Option < string > (
45
+ var optZip = new Option < FileInfo ? > (
51
46
new [ ] { "-z" , "--zip" } ,
52
- "Generates a compressed ZIP archive of the published contents." ) ) ;
47
+ "Generates a compressed ZIP archive of the published contents." ) ;
53
48
54
- Command . AddOption ( new Option < bool > (
49
+ var optClean = new Option < bool > (
55
50
new [ ] { "-c" , "--clean" } , ( ) => false ,
56
- "Generates a compressed ZIP archive of the published contents." ) ) ;
51
+ "Generates a compressed ZIP archive of the published contents." ) ;
57
52
58
- Command . AddOption ( new Option < int > (
53
+ var optConcurrency = new Option < int > (
59
54
new [ ] { "--concurrency" } , ConcurrencyHelper . GetDefaultValue ,
60
- "Sets the level of concurrency for importing/publishing files. Default value is half of the system processor count." ) ) ;
55
+ "Sets the level of concurrency for importing/publishing files. Default value is half of the system processor count." ) ;
56
+
57
+ Command = new Command ( "publish" , "Publishes the specified profile." ) {
58
+ optProjectFile ,
59
+ optProfileName ,
60
+ optDestination ,
61
+ optZip ,
62
+ optClean ,
63
+ optConcurrency ,
64
+ } ;
65
+
66
+ Command . SetHandler ( RunAsync , optProjectFile , optProfileName , optDestination , optZip , optClean , optConcurrency ) ;
61
67
}
62
68
63
- private async Task < int > RunAsync ( FileInfo projectFile , string profileName , DirectoryInfo destination , FileInfo ? zip , bool clean , int concurrency )
69
+ private async Task < int > RunAsync ( FileInfo projectFile , string profileName , DirectoryInfo ? destination , FileInfo ? zip , bool clean , int concurrency )
64
70
{
65
- var destPath = zip ? . FullName ?? destination . FullName ;
71
+ var destPath = zip ? . FullName ?? destination ? . FullName ;
72
+ if ( destPath == null ) throw new ApplicationException ( "Publish output location is undefined!" ) ;
73
+
74
+ var sourcePath = projectFile . DirectoryName ;
75
+ if ( sourcePath == null ) throw new ApplicationException ( "Source directory is undefined!" ) ;
66
76
67
77
try {
68
78
if ( projectFile . Exists != true )
@@ -103,7 +113,7 @@ private async Task<int> RunAsync(FileInfo projectFile, string profileName, Direc
103
113
executor . CleanDestination = clean ;
104
114
executor . AsArchive = zip != null ;
105
115
106
- await executor . ExecuteAsync ( projectFile . DirectoryName , destPath , lifetime . Token ) ;
116
+ await executor . ExecuteAsync ( sourcePath , destPath , lifetime . Token ) ;
107
117
108
118
return 0 ;
109
119
}
0 commit comments