Enum Action

Source
pub enum Action {
    Help(String, PathBuf),
    List(String),
    Execute {
        launcher_path: PathBuf,
        executable: PathBuf,
        args: Vec<String>,
    },
}
Expand description

Represents the possible outcomes based on CLI arguments.

Variants§

§

Help(String, PathBuf)

The help string for the Python Launcher along with the path to a Python executable.

The executable path is so that it can be executed with -h to append Python’s own help output.

§

List(String)

A string listing all found executables on PATH.

The string is formatted to be human-readable.

§

Execute

Details for executing a Python executable.

Fields

§launcher_path: PathBuf

The Python Launcher used to find the Python executable.

§executable: PathBuf

The Python executable to run.

§args: Vec<String>

Arguments to the executable.

Implementations§

Source§

impl Action

Source

pub fn from_main(argv: &[String]) -> Result<Self>

Parses CLI arguments to determine what action should be taken.

The first argument – argv[0] – is considered the path to the Launcher itself (i.e. Action::Execute::launcher_path).

The second argument – argv.get(1) – is used to determine if/what argument has been provided for the Launcher.

§Launcher Arguments
§-h/--help

Returns Action::Help.

The search for the Python executable to use is done using crate::find_executable with an RequestedVersion::Any argument.

§--list

Returns Action::List.

The list of executable is gathered via crate::all_executables.

§Version Restriction

Returns the appropriate Action::Execute instance for the requested Python version.

crate::find_executable is used to perform the search.

§No Arguments for the Launcher

Returns an Action::Execute instance.

As a first step, a check is done for an activated virtual environment via the VIRTUAL_ENV environment variable. If none is set, look for a virtual environment in a directory named by DEFAULT_VENV_DIR in the current or any parent directories.

If no virtual environment is found, a shebang line is searched for in the first argument to the Python interpreter. If one is found then it is used to (potentially) restrict the requested version searched for.

The search for an interpreter proceeds using crate::find_executable.

§Errors

If -h, --help, or --list are specified as the first argument but there are other arguments, crate::Error::IllegalArgument is returned.

If no executable could be found for Action::Help or Action::List, crate::Error::NoExecutableFound is returned.

§Panics
  • If a writeln! call fails.
  • If the current directory cannot be accessed.

Trait Implementations§

Source§

impl Clone for Action

Source§

fn clone(&self) -> Action

Returns a copy 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 Action

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for Action

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Action

Source§

fn eq(&self, other: &Action) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Action

Source§

impl StructuralPartialEq for Action

Auto Trait Implementations§

§

impl Freeze for Action

§

impl RefUnwindSafe for Action

§

impl Send for Action

§

impl Sync for Action

§

impl Unpin for Action

§

impl UnwindSafe for Action

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.