lux_cli/
lib.rs

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