FlossCli

Struct FlossCli 

Source
#[non_exhaustive]
pub struct FlossCli { /* private fields */ }
Expand description

FLOSS CLI 入口配置(可执行文件名/路径、基础参数、工作目录与环境变量)。

Implementations§

Source§

impl FlossCli

Source

pub fn command(&self) -> FlossCommand

构建一次调用(可继续追加参数、可选追加样本路径),最后用 run/run_raw/run_json 执行。

Source

pub async fn detect() -> Result<Self>

自动探测调用方式:

  1. 若设置 FLOSS_EXE,优先使用该值作为可执行文件;
  2. 若设置 FLOSS_PYTHON,优先尝试 FLOSS_PYTHON {FLOSS_PYTHON_ARGS} -m floss -h
  3. 否则检测 PATH 中是否存在 floss.exe(Windows)或 floss(其他系统);
  4. 最后尝试 Python:Windows 依次尝试 python/python3/py -3,其他系统依次尝试 python3/python
§Errors
  • 当既找不到可执行的 floss,也找不到可运行 python -m floss 的 Python 时,返回 FlossError::AutoDetectFailed
Source

pub async fn help(&self) -> Result<String>

等价于执行 floss -h,返回 stdout。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当 stdout 不是有效 UTF-8 时,返回 FlossError::Utf8
Source

pub async fn help_all(&self) -> Result<String>

等价于执行 floss -H,返回 stdout(包含高级参数)。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当 stdout 不是有效 UTF-8 时,返回 FlossError::Utf8
Source

pub fn new<Program>(program: Program) -> Self
where Program: Into<OsString>,

使用一个可执行程序名/路径创建实例,例如:flossfloss.exe 或绝对路径。

Source

pub fn program(&self) -> &OsStr

返回当前配置使用的可执行程序(或 Python 解释器)路径/名称。

Source

pub fn python_module<Python>(python: Python) -> Self
where Python: Into<OsString>,

通过 python -m floss 方式调用(适合只安装了 Python 包、没有独立 floss 可执行文件的场景)。

Source

pub async fn version(&self) -> Result<String>

等价于执行 floss --version,返回 stdout。

§Errors
  • 当启动进程失败时,返回 FlossError::Io
  • 当 stdout 不是有效 UTF-8 时,返回 FlossError::Utf8
Source

pub fn with_current_dir<Dir>(self, dir: Dir) -> Self
where Dir: Into<PathBuf>,

设置工作目录(Command::current_dir)。

Source

pub fn with_env<Key, Value>(self, key: Key, value: Value) -> Self
where Key: Into<OsString>, Value: Into<OsString>,

增加环境变量(Command::env)。

Source

pub const fn with_timeout(self, timeout: Duration) -> Self

设置执行超时:超过该时间会尝试终止子进程并返回 FlossError::TimedOut。 若无法终止子进程,则返回 FlossError::TimedOutKillFailed。 若无法终止子进程,则返回 FlossError::TimedOutKillFailed

Trait Implementations§

Source§

impl Clone for FlossCli

Source§

fn clone(&self) -> FlossCli

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FlossCli

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.