@@ -123,15 +123,18 @@ fn make_interactive(
123123
124124/// Completes the build of an interactive machine by taking a partial builder and running post-build
125125/// steps on it.
126+ ///
127+ /// `service_url` is the base URL of the cloud service.
126128fn finish_interactive_build (
127129 mut builder : endbasic_std:: InteractiveMachineBuilder ,
130+ service_url : & str ,
128131) -> endbasic_core:: exec:: Result < endbasic_core:: exec:: Machine > {
129132 let console = builder. get_console ( ) ;
130133 let storage = builder. get_storage ( ) ;
131134
132135 let mut machine = builder. build ( ) ?;
133136
134- let service = Rc :: from ( RefCell :: from ( endbasic_client:: CloudService :: default ( ) ) ) ;
137+ let service = Rc :: from ( RefCell :: from ( endbasic_client:: CloudService :: new ( service_url ) ? ) ) ;
135138 endbasic_client:: add_all ( & mut machine, service, console, storage) ;
136139
137140 Ok ( machine)
@@ -225,9 +228,11 @@ pub fn setup_storage(storage: &mut Storage, local_drive_spec: &str) -> io::Resul
225228/// Enters the interactive interpreter.
226229///
227230/// `local_drive` is the optional local drive to mount and use as the default location.
231+ /// `service_url` is the base URL of the cloud service.
228232async fn run_repl_loop (
229233 console_spec : Option < & str > ,
230234 local_drive_spec : & str ,
235+ service_url : & str ,
231236) -> endbasic_core:: exec:: Result < i32 > {
232237 let mut builder = make_interactive ( new_machine_builder ( console_spec) ?) ;
233238
@@ -237,7 +242,7 @@ async fn run_repl_loop(
237242 let storage = builder. get_storage ( ) ;
238243 setup_storage ( & mut storage. borrow_mut ( ) , local_drive_spec) ?;
239244
240- let mut machine = finish_interactive_build ( builder) ?;
245+ let mut machine = finish_interactive_build ( builder, service_url ) ?;
241246 endbasic_repl:: print_welcome ( console. clone ( ) ) ?;
242247 endbasic_repl:: try_load_autoexec ( & mut machine, console. clone ( ) , storage) . await ?;
243248 Ok ( endbasic_repl:: run_repl_loop ( & mut machine, console, program) . await ?)
@@ -256,17 +261,19 @@ async fn run_script<P: AsRef<Path>>(
256261/// Executes the `path` program in a fresh machine allowing any interactive-only calls.
257262///
258263/// `local_drive` is the optional local drive to mount and use as the default location.
264+ /// `service_url` is the base URL of the cloud service.
259265async fn run_interactive < P : AsRef < Path > > (
260266 path : P ,
261267 console_spec : Option < & str > ,
262268 local_drive_spec : & str ,
269+ service_url : & str ,
263270) -> endbasic_core:: exec:: Result < i32 > {
264271 let mut builder = make_interactive ( new_machine_builder ( console_spec) ?) ;
265272
266273 let storage = builder. get_storage ( ) ;
267274 setup_storage ( & mut storage. borrow_mut ( ) , local_drive_spec) ?;
268275
269- let mut machine = finish_interactive_build ( builder) ?;
276+ let mut machine = finish_interactive_build ( builder, service_url ) ?;
270277 let mut input = File :: open ( path) ?;
271278 Ok ( machine. exec ( & mut input) . await ?. as_exit_code ( ) )
272279}
@@ -280,6 +287,7 @@ async fn safe_main(name: &str, args: env::Args) -> Result<i32> {
280287 opts. optflag ( "h" , "help" , "show command-line usage information and exit" ) ;
281288 opts. optflag ( "i" , "interactive" , "force interactive mode when running a script" ) ;
282289 opts. optopt ( "" , "local-drive" , "location of the drive to mount as LOCAL" , "URI" ) ;
290+ opts. optopt ( "" , "service-url" , "base URL of the cloud service" , "URL" ) ;
283291 opts. optflag ( "" , "version" , "show version information and exit" ) ;
284292 let matches = opts. parse ( args) ?;
285293
@@ -295,15 +303,20 @@ async fn safe_main(name: &str, args: env::Args) -> Result<i32> {
295303
296304 let console_spec = matches. opt_str ( "console" ) ;
297305
306+ let service_url = matches
307+ . opt_str ( "service-url" )
308+ . unwrap_or_else ( || endbasic_client:: PROD_API_ADDRESS . to_owned ( ) ) ;
309+
298310 match matches. free . as_slice ( ) {
299311 [ ] => {
300312 let local_drive = get_local_drive_spec ( matches. opt_str ( "local-drive" ) ) ?;
301- Ok ( run_repl_loop ( console_spec. as_deref ( ) , & local_drive) . await ?)
313+ Ok ( run_repl_loop ( console_spec. as_deref ( ) , & local_drive, & service_url ) . await ?)
302314 }
303315 [ file] => {
304316 if matches. opt_present ( "interactive" ) {
305317 let local_drive = get_local_drive_spec ( matches. opt_str ( "local-drive" ) ) ?;
306- Ok ( run_interactive ( file, console_spec. as_deref ( ) , & local_drive) . await ?)
318+ Ok ( run_interactive ( file, console_spec. as_deref ( ) , & local_drive, & service_url)
319+ . await ?)
307320 } else {
308321 Ok ( run_script ( file, console_spec. as_deref ( ) ) . await ?)
309322 }
0 commit comments