lux_cli/
lib.rs

1use crate::project::NewProject;
2use std::path::PathBuf;
3
4use add::Add;
5use build::Build;
6use clap::{Parser, Subcommand};
7use config::ConfigCmd;
8use debug::Debug;
9use doc::Doc;
10use download::Download;
11use exec::Exec;
12use generate_rockspec::GenerateRockspec;
13use info::Info;
14use install::Install;
15use install_rockspec::InstallRockspec;
16use list::ListCmd;
17use lux_lib::config::LuaVersion;
18use outdated::Outdated;
19use pack::Pack;
20use path::Path;
21use pin::ChangePin;
22use remove::Remove;
23use run::Run;
24use run_lua::RunLua;
25use search::Search;
26use test::Test;
27use uninstall::Uninstall;
28use update::Update;
29use upload::Upload;
30use url::Url;
31use which::Which;
32
33pub mod add;
34pub mod build;
35pub mod check;
36pub mod config;
37pub mod debug;
38pub mod doc;
39pub mod download;
40pub mod exec;
41pub mod fetch;
42pub mod format;
43pub mod generate_rockspec;
44pub mod info;
45pub mod install;
46pub mod install_lua;
47pub mod install_rockspec;
48pub mod list;
49pub mod outdated;
50pub mod pack;
51pub mod path;
52pub mod pin;
53pub mod project;
54pub mod purge;
55pub mod remove;
56pub mod run;
57pub mod run_lua;
58pub mod search;
59pub mod test;
60pub mod uninstall;
61pub mod unpack;
62pub mod update;
63pub mod upload;
64pub mod utils;
65pub mod which;
66
67/// A luxurious package manager for Lua.
68#[derive(Parser)]
69#[command(author, version, about, long_about = None, arg_required_else_help = true)]
70pub struct Cli {
71    /// Enable the sub-repositories in luarocks servers for
72    /// rockspecs of in-development versions.
73    #[arg(long)]
74    pub dev: bool,
75
76    /// Fetch rocks/rockspecs from this server (takes priority
77    /// over config file).
78    #[arg(long, value_name = "server")]
79    pub server: Option<Url>,
80
81    /// Fetch rocks/rockspecs from this server in addition to the main server
82    /// (overrides any entries in the config file).
83    #[arg(long, value_name = "extra-server")]
84    pub extra_servers: Option<Vec<Url>>,
85
86    /// Restrict downloads to paths matching the given URL.
87    #[arg(long, value_name = "url")]
88    pub only_sources: Option<String>,
89
90    /// Specify the luarocks server namespace to use.
91    #[arg(long, value_name = "namespace")]
92    pub namespace: Option<String>,
93
94    /// Specify the luarocks server namespace to use.
95    #[arg(long, value_name = "prefix")]
96    pub lua_dir: Option<PathBuf>,
97
98    /// Which Lua installation to use.
99    /// Valid versions are: '5.1', '5.2', '5.3', '5.4', 'jit' and 'jit52'.
100    #[arg(long, value_name = "ver")]
101    pub lua_version: Option<LuaVersion>,
102
103    /// Which tree to operate on.
104    #[arg(long, value_name = "tree")]
105    pub tree: Option<PathBuf>,
106
107    /// Specifies the cache directory for e.g. luarocks manifests.
108    #[arg(long, value_name = "path")]
109    pub cache_path: Option<PathBuf>,
110
111    /// Do not use project tree even if running from a project folder.
112    #[arg(long)]
113    pub no_project: bool,
114
115    /// Display verbose output of commands executed.
116    #[arg(long)]
117    pub verbose: bool,
118
119    /// Configure lux for installing Neovim packages.
120    #[arg(long)]
121    pub nvim: bool,
122
123    /// Timeout on network operations, in seconds.
124    /// 0 means no timeout (wait forever). Default is 30.
125    #[arg(long, value_name = "seconds")]
126    pub timeout: Option<usize>,
127
128    #[command(subcommand)]
129    pub command: Commands,
130}
131
132#[derive(Subcommand)]
133pub enum Commands {
134    /// Add a dependency to the current project.
135    Add(Add),
136    /// Build/compile a project.
137    Build(Build),
138    /// Runs `luacheck` in the current project.
139    Check,
140    /// Interact with the lux configuration.
141    #[command(subcommand, arg_required_else_help = true)]
142    Config(ConfigCmd),
143    /// Internal commands for debugging Lux itself.
144    #[command(subcommand, arg_required_else_help = true)]
145    Debug(Debug),
146    /// Show documentation for an installed rock.
147    Doc(Doc),
148    /// Download a specific rock file from a luarocks server.
149    #[command(arg_required_else_help = true)]
150    Download(Download),
151    /// Formats the codebase with stylua.
152    Fmt,
153    /// Generate a rockspec file from a project.
154    GenerateRockspec(GenerateRockspec),
155    /// Show metadata for any rock.
156    Info(Info),
157    /// Install a rock for use on the system.
158    #[command(arg_required_else_help = true)]
159    Install(Install),
160    /// Install a local rockspec for use on the system.
161    #[command(arg_required_else_help = true)]
162    InstallRockspec(InstallRockspec),
163    /// Manually install and manage Lua headers for various Lua versions.
164    InstallLua,
165    /// [UNIMPLEMENTED] Check syntax of a rockspec.
166    Lint,
167    /// List currently installed rocks.
168    List(ListCmd),
169    /// Run lua, with the `LUA_PATH` and `LUA_CPATH` set to the specified lux tree.
170    Lua(RunLua),
171    /// Create a new Lua project.
172    New(NewProject),
173    /// List outdated rocks.
174    Outdated(Outdated),
175    /// Create a packed rock for distribution, packing sources or binaries.
176    Pack(Pack),
177    /// Return the currently configured package path.
178    Path(Path),
179    /// Pin an existing rock, preventing any updates to the package.
180    Pin(ChangePin),
181    /// Remove all installed rocks from a tree.
182    Purge,
183    /// Remove a rock from the current project's lux.toml dependencies.
184    Remove(Remove),
185    /// Run the current project with the provided arguments.
186    Run(Run),
187    /// Execute a command that has been installed with lux.
188    /// If the command is not found, a package named after the command
189    /// will be installed.
190    Exec(Exec),
191    /// Query the luarocks servers.
192    #[command(arg_required_else_help = true)]
193    Search(Search),
194    /// Run the test suite in the current directory.
195    Test(Test),
196    /// Uninstall a rock from the system.
197    Uninstall(Uninstall),
198    /// Unpins an existing rock, allowing updates to alter the package.
199    Unpin(ChangePin),
200    /// Updates all rocks in a project.
201    Update(Update),
202    /// Upload a rockspec to the public luarocks repository.
203    Upload(Upload),
204    /// Tell which file corresponds to a given module name.
205    Which(Which),
206}