MCPcopy Index your code
hub / github.com/endbasic/endbasic / run_interactive

Function run_interactive

cli/src/lib.rs:124–179  ·  view source on GitHub ↗

Executes the `path` program in a fresh machine allowing any interactive-only calls. `local_drive` is the optional local drive to mount and use as the default location. `service_url` is the base URL of the cloud service. If `path` starts with `cloud://`, this uses the same auto-run features that the web UI exposes. The presence of this here is kind of a hack but avoids having too much logic just

(
    path: &str,
    console_factory: Box<dyn ConsoleFactory>,
    signals_chan: (Sender<Signal>, Receiver<Signal>),
    gpio_pins_spec: Option<&str>,
    local_drive_spec: &str,
    service_url: &st

Source from the content-addressed store, hash-verified

122/// exposes. The presence of this here is kind of a hack but avoids having too much logic
123/// just in the web and helps test this feature.
124pub async fn run_interactive(
125 path: &str,
126 console_factory: Box<dyn ConsoleFactory>,
127 signals_chan: (Sender<Signal>, Receiver<Signal>),
128 gpio_pins_spec: Option<&str>,
129 local_drive_spec: &str,
130 service_url: &str,
131) -> Result<i32> {
132 let mut builder = new_machine_builder(console_factory, signals_chan, gpio_pins_spec)?;
133 let console = builder.get_console();
134 let program = Rc::from(RefCell::from(endbasic_repl::editor::Editor::default()));
135 let storage = Rc::from(RefCell::from(Storage::default()));
136 setup_storage(&mut storage.borrow_mut(), local_drive_spec)?;
137
138 let service = Rc::from(RefCell::from(CloudService::new(service_url)?));
139 endbasic_client::add_all(
140 &mut builder,
141 service,
142 console.clone(),
143 storage.clone(),
144 "https://repl.endbasic.dev/",
145 );
146
147 let mut machine = builder
148 .make_interactive()
149 .with_program(program.clone())
150 .with_storage(storage.clone())
151 .build();
152
153 match path.strip_prefix("cloud://") {
154 Some(username_path) => {
155 let path =
156 endbasic_repl::mount_cloud_share(console.clone(), storage.clone(), username_path)?;
157 let code = endbasic_repl::run_from_storage_path(
158 &mut machine,
159 console.clone(),
160 storage.clone(),
161 program.clone(),
162 &path,
163 false,
164 )
165 .await?;
166 Ok(code)
167 }
168 None => {
169 let mut input = File::open(path)?;
170 machine.compile(&mut input)?;
171 match machine.exec().await {
172 Ok(Some(code)) => Ok(code),
173 Ok(None) => Ok(0),
174 Err(StdError::Break) => Ok(INTERRUPTED_EXIT_CODE),
175 Err(e) => Err(e.into()),
176 }
177 }
178 }
179}
180
181/// Representation of the CLI execution mode and the arguments required for each.

Callers 1

async_app_mainFunction · 0.85

Calls 12

new_machine_builderFunction · 0.85
mount_cloud_shareFunction · 0.85
run_from_storage_pathFunction · 0.85
with_storageMethod · 0.80
with_programMethod · 0.80
make_interactiveMethod · 0.80
setup_storageFunction · 0.70
add_allFunction · 0.50
get_consoleMethod · 0.45
buildMethod · 0.45
compileMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected