11namespace rune . cmd
22{
3- using System ;
43 using System . Collections . Generic ;
54 using System . ComponentModel ;
65 using System . IO ;
7- using System . IO . Compression ;
86 using System . Linq ;
97 using System . Threading . Tasks ;
108 using cli ;
119 using etc ;
1210 using etc . ExternalCommand ;
1311 using Internal ;
14- using MoreLinq ;
12+ using static System . Console ;
1513
1614 public class VMCommand : RuneCommand < VMCommand > , IWithProject
1715 {
@@ -24,8 +22,6 @@ internal override CommandLineApplication Setup()
2422 Description = "Execute project in Ancient VM"
2523 } ;
2624
27- app . Command ( "install" , InstallVM ) ;
28-
2925 app . HelpOption ( "-h|--help" ) ;
3026 var dotnetBuild = new BuildCommand ( ) ;
3127 var vm = new VMCommand ( ) ;
@@ -42,79 +38,15 @@ internal override CommandLineApplication Setup()
4238 } ) ;
4339 return app ;
4440 }
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+
11042 internal async Task < int > Execute ( CommandOption isDebug , CommandOption keepMemory , CommandOption fastWrite , CommandOption isInteractive )
11143 {
11244 var dir = Directory . GetCurrentDirectory ( ) ;
11345 if ( ! this . Validate ( dir ) )
11446 return await Fail ( ) ;
11547
11648 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 '") ;
11850
11951
12052 var vm_bin = Dirs . Bin . VM . FullName ;
@@ -148,16 +80,11 @@ internal async Task<int> Execute(CommandOption isDebug, CommandOption keepMemory
14880 . Wait ( )
14981 . ExitCode ( ) ;
15082 }
151- catch ( Win32Exception e )
83+ catch ( Win32Exception e ) // AccessDenied on linux
15284 {
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.") ;
15687 }
157- return result
158- . Start ( )
159- . Wait ( )
160- . ExitCode ( ) ;
16188 }
16289 }
16390}
0 commit comments