Sign in

    which

    A Moonbit equivalent of Unix command "which". Locate installed executable in cross platforms.

    which
    moonbit
    Download zip
    Version
    0.1.3
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    43

    #which-mbt

    A cross-platform Unix which command tool implemented in Moonbit, designed to locate installed executables.

    #Supported Platforms

    • Windows
    • macOS
    • Linux

    #Installation

    moon update moon add FrenchPicnic/which

    #Usage

    Example: Use which to find the path of the moon executable on your system.

    /// Locate the path of 'moon'
    let pth = @which.which?("moon")
    match pth {
    Ok(x) => println(x)
    Err(e) => println(e)
    }
    This program is expected to output the path of your moon executable.

    #Notes

    • The current WSAM environment does not support accessing the host system environment. Therefore, you must specify the compilation target as native/llvm or js.
    • For non-Windows platforms, js target requires root privileges to execute.

    Example:
    moon run xxx.mbt --target native

    #Documentation

    Refer to the documentation on Mooncake or read the source code.

    WhichError

    pub enum WhichError {
    PathNotFound(String)
    UnknownPlatform(String)
    UnSupportedPlatform(String)
    FileNotFound(String)
    }

    impl Show for WhichError

    which

    fn which(filename : String) -> String!WhichError
    Find the first matching file in environment variables based on the given filename

    Parameters

    • filename : The string representing the path to be checked.

    Returns

    • String : the absolute path of the file

    which_all

    fn which_all(filename : String) -> Array[String]!WhichError
    Find all matching files in environment variables based on the given filename

    which_in

    fn which_in(filename : String, filepath : Array[String]) -> String!WhichError
    Find the first matching file based on the given filename and filepath

    Parameters

    • filename : The string representing the path to be checked.

    • filepath : A string array containing all paths to be searched.

    Returns

    • String : the absolute path of the file

    which_in_all

    fn which_in_all(filename : String, filepath : Array[String]) -> Array[String]!WhichError
    Find all matching file based on the given filename and filepath

    Parameters

    • filename : The string representing the path to be checked.

    • filepath : A string array containing all paths to be searched.

    Returns

    • Array[String] : A string array containing all the file in given filepath

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io