1
1
namespace rune . cmd
2
2
{
3
- using System ;
4
3
using System . Collections . Generic ;
5
4
using System . ComponentModel ;
6
5
using System . IO ;
7
- using System . IO . Compression ;
8
6
using System . Linq ;
9
7
using System . Threading . Tasks ;
10
8
using cli ;
11
9
using etc ;
12
10
using etc . ExternalCommand ;
13
11
using Internal ;
14
- using MoreLinq ;
12
+ using static System . Console ;
15
13
16
14
public class VMCommand : RuneCommand < VMCommand > , IWithProject
17
15
{
@@ -24,8 +22,6 @@ internal override CommandLineApplication Setup()
24
22
Description = "Execute project in Ancient VM"
25
23
} ;
26
24
27
- app . Command ( "install" , InstallVM ) ;
28
-
29
25
app . HelpOption ( "-h|--help" ) ;
30
26
var dotnetBuild = new BuildCommand ( ) ;
31
27
var vm = new VMCommand ( ) ;
@@ -42,79 +38,15 @@ internal override CommandLineApplication Setup()
42
38
} ) ;
43
39
return app ;
44
40
}
45
-
46
- internal void InstallACC ( CommandLineApplication app )
47
- {
48
- app . Description = $ "Install latest ancient compiler.";
49
- var force = app . Option ( "-f|--force" , "Force install binaries?" , CommandOptionType . BoolValue ) ;
50
-
51
- bool isForce ( ) => force . HasValue ( ) && force . BoolValue != null && force . BoolValue . Value ;
52
- app . OnExecute ( async ( ) =>
53
- {
54
- try
55
- {
56
- if ( ! isForce ( ) && Dirs . CompilerFolder . EnumerateFiles ( ) . Any ( ) )
57
- return await Fail ( $ "{ ":x:" . Emoji ( ) } { "Already" . Nier ( 2 ) } installed. Try rune vm install compiler --force") ;
58
-
59
-
60
- if ( Dirs . CompilerFolder . EnumerateFiles ( ) . Any ( ) )
61
- _ = Dirs . CompilerFolder . EnumerateFiles ( ) . Pipe ( x => x . Delete ( ) ) . ToArray ( ) ;
62
-
63
- var result = await Appx . By ( AppxType . acc )
64
- . DownloadAsync ( ) ;
65
- Console . Write ( $ "{ ":open_file_folder:" . Emoji ( ) } Extract files") ;
66
- await RuneTask . Fire ( ( ) =>
67
- ZipFile . ExtractToDirectory ( result . FullName , Dirs . CompilerFolder . FullName ) ) ;
68
- }
69
- catch ( Exception e )
70
- {
71
- Console . WriteLine ( e ) ;
72
- }
73
- return await Success ( ) ;
74
- } ) ;
75
- }
76
-
77
- internal void InstallVM ( CommandLineApplication app )
78
- {
79
- app . Description = $ "Install latest ancient VM.";
80
- var force = app . Option ( "-f|--force" , "Force install binaries?" , CommandOptionType . BoolValue ) ;
81
-
82
- bool isForce ( ) => force . HasValue ( ) && force . BoolValue != null && force . BoolValue . Value ;
83
- app . Command ( "compiler" , InstallACC ) ;
84
- app . OnExecute ( async ( ) =>
85
- {
86
- try
87
- {
88
- if ( ! isForce ( ) && Dirs . VMFolder . EnumerateFiles ( ) . Any ( ) )
89
- return await Fail ( $ "{ ":x:" . Emoji ( ) } { "Already" . Nier ( 2 ) } installed. Try rune vm install --force") ;
90
-
91
-
92
- if ( Dirs . VMFolder . EnumerateFiles ( ) . Any ( ) )
93
- _ = Dirs . VMFolder . EnumerateFiles ( ) . Pipe ( x => x . Delete ( ) ) . ToArray ( ) ;
94
-
95
- var result = await Appx . By ( AppxType . vm )
96
- . DownloadAsync ( ) ;
97
- Console . Write ( $ "{ ":open_file_folder:" . Emoji ( ) } Extract files") ;
98
- await RuneTask . Fire ( ( ) =>
99
- ZipFile . ExtractToDirectory ( result . FullName , Dirs . VMFolder . FullName ) ) ;
100
- }
101
- catch ( Exception e )
102
- {
103
- Console . WriteLine ( e ) ;
104
- }
105
- return await Success ( ) ;
106
- } ) ;
107
- }
108
-
109
-
41
+
110
42
internal async Task < int > Execute ( CommandOption isDebug , CommandOption keepMemory , CommandOption fastWrite , CommandOption isInteractive )
111
43
{
112
44
var dir = Directory . GetCurrentDirectory ( ) ;
113
45
if ( ! this . Validate ( dir ) )
114
46
return await Fail ( ) ;
115
47
116
48
if ( ! Dirs . Bin . VM . Exists )
117
- return await Fail ( $ "VM is not installed. Try 'rune vm install'") ;
49
+ return await Fail ( $ "VM is not installed. Try 'rune install vm '") ;
118
50
119
51
120
52
var vm_bin = Dirs . Bin . VM . FullName ;
@@ -148,16 +80,11 @@ internal async Task<int> Execute(CommandOption isDebug, CommandOption keepMemory
148
80
. Wait ( )
149
81
. ExitCode ( ) ;
150
82
}
151
- catch ( Win32Exception e )
83
+ catch ( Win32Exception e ) // AccessDenied on linux
152
84
{
153
- Console . WriteLine ( $ "{ ":x:" . Emoji ( ) } { e . Message } ") ;
154
- Console . WriteLine ( $ "{ "TODO" } try fix...") ;
155
- await OS . FireAsync ( $ "chmod +x \" { vm_bin } \" ") ;
85
+ WriteLine ( $ "{ ":x:" . Emoji ( ) } { e . Message } ") ;
86
+ return await Fail ( $ "Run [chmod +x \" { vm_bin } \" ] for resolve this problem.") ;
156
87
}
157
- return result
158
- . Start ( )
159
- . Wait ( )
160
- . ExitCode ( ) ;
161
88
}
162
89
}
163
90
}
0 commit comments