-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathcli.rs
More file actions
31 lines (25 loc) · 872 Bytes
/
cli.rs
File metadata and controls
31 lines (25 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use pyo3::exceptions::PyRuntimeError;
use pyo3::prelude::*;
use crate::SESSION;
use crate::TOKIO_RUNTIME;
use crate::install_module;
pub(crate) fn init(py: Python, parent: &Bound<PyModule>) -> PyResult<()> {
let m = PyModule::new(py, "cli")?;
parent.add_submodule(&m)?;
install_module("vortex._lib.cli", &m)?;
m.add_function(wrap_pyfunction!(launch, &m)?)?;
Ok(())
}
/// Launch the `vx` CLI with the given arguments.
///
/// Parameters
/// ----------
/// args : list[str]
/// Command-line arguments, typically ``sys.argv``.
#[pyfunction]
fn launch(py: Python, args: Vec<String>) -> PyResult<()> {
py.detach(|| TOKIO_RUNTIME.block_on(vortex_tui::launch_from(&SESSION, args)))
.map_err(|e| PyRuntimeError::new_err(e.to_string()))
}