Skip to content

Commit

Permalink
Merge pull request #379 from moonbitlang/add-package-subcommand
Browse files Browse the repository at this point in the history
feat: add `moon package` subcommand
  • Loading branch information
lijunchen authored Oct 12, 2024
2 parents 01291fc + 6ff78ab commit e7d1728
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 8 deletions.
3 changes: 2 additions & 1 deletion crates/moon/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use moonutil::{
read_module_desc_file_in_dir, BuildPackageFlags, LinkCoreFlags, MooncOpt, OutputFormat,
SurfaceTarget, TargetBackend, MOONBITLANG_CORE, MOON_MOD_JSON,
},
mooncakes::{LoginSubcommand, PublishSubcommand, RegisterSubcommand},
mooncakes::{LoginSubcommand, PackageSubcommand, PublishSubcommand, RegisterSubcommand},
};
use std::path::Path;

Expand Down Expand Up @@ -110,6 +110,7 @@ pub enum MoonBuildSubcommands {
Login(LoginSubcommand),
Register(RegisterSubcommand),
Publish(PublishSubcommand),
Package(PackageSubcommand),

Update(UpdateSubcommand),

Expand Down
13 changes: 12 additions & 1 deletion crates/moon/src/cli/mooncake_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use anyhow::bail;
use moonutil::{
cli::UniversalFlags,
mooncake_bin::call_mooncake,
mooncakes::{LoginSubcommand, MooncakeSubcommands, PublishSubcommand, RegisterSubcommand},
mooncakes::{
LoginSubcommand, MooncakeSubcommands, PackageSubcommand, PublishSubcommand,
RegisterSubcommand,
},
};
use serde::Serialize;

Expand Down Expand Up @@ -89,3 +92,11 @@ pub fn publish_cli(cli: UniversalFlags, cmd: PublishSubcommand) -> anyhow::Resul
&["--read-args-from-stdin"],
)
}

pub fn package_cli(cli: UniversalFlags, cmd: PackageSubcommand) -> anyhow::Result<i32> {
execute_cli(
cli,
MooncakeSubcommands::Package(cmd),
&["--read-args-from-stdin"],
)
}
1 change: 1 addition & 0 deletions crates/moon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ fn main1() -> anyhow::Result<i32> {
Login(l) => cli::mooncake_adapter::login_cli(flags, l),
New(n) => cli::run_new(&flags, n),
Publish(p) => cli::mooncake_adapter::publish_cli(flags, p),
Package(p) => cli::mooncake_adapter::package_cli(flags, p),
Register(r) => cli::mooncake_adapter::register_cli(flags, r),
Remove(r) => cli::remove_cli(flags, r),
Run(r) => cli::run_run(&flags, r),
Expand Down
3 changes: 2 additions & 1 deletion crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ fn test_moon_help() {
tree Display the dependency tree
login Log in to your account
register Register an account at mooncakes.io
publish Publish the current package
publish Publish the current module
package Package the current module
update Update the package registry index
coverage Code coverage utilities
generate-build-matrix Generate build matrix for benchmarking (legacy feature)
Expand Down
13 changes: 12 additions & 1 deletion crates/moonutil/src/mooncakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ pub enum MooncakeSubcommands {
Login(LoginSubcommand),
Register(RegisterSubcommand),
Publish(PublishSubcommand),
Package(PackageSubcommand),
}

/// Log in to your account
Expand All @@ -422,13 +423,23 @@ pub struct LoginSubcommand {}
#[derive(Debug, clap::Parser, Serialize, Deserialize)]
pub struct RegisterSubcommand {}

/// Publish the current package
/// Publish the current module
#[derive(Debug, clap::Parser, Serialize, Deserialize)]
pub struct PublishSubcommand {
#[clap(flatten)]
pub auto_sync_flags: AutoSyncFlags,
}

/// Package the current module
#[derive(Debug, clap::Parser, Serialize, Deserialize)]
pub struct PackageSubcommand {
#[clap(flatten)]
pub auto_sync_flags: AutoSyncFlags,

#[clap(long)]
pub list: bool,
}

// username rule
// at least 5 char, at most 39 char
// may contain [a-z] [0-9] [A-Z] '-' '_'
Expand Down
19 changes: 17 additions & 2 deletions docs/manual-zh/src/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This document contains the help content for the `moon` command-line program.
* [`moon login`](#moon-login)
* [`moon register`](#moon-register)
* [`moon publish`](#moon-publish)
* [`moon package`](#moon-package)
* [`moon update`](#moon-update)
* [`moon coverage`](#moon-coverage)
* [`moon coverage report`](#moon-coverage-report)
Expand Down Expand Up @@ -51,7 +52,8 @@ This document contains the help content for the `moon` command-line program.
* `tree` — Display the dependency tree
* `login` — Log in to your account
* `register` — Register an account at mooncakes.io
* `publish` — Publish the current package
* `publish` — Publish the current module
* `package` — Package the current module
* `update` — Update the package registry index
* `coverage` — Code coverage utilities
* `generate-build-matrix` — Generate build matrix for benchmarking (legacy feature)
Expand Down Expand Up @@ -317,7 +319,7 @@ Register an account at mooncakes.io

## `moon publish`

Publish the current package
Publish the current module

**Usage:** `moon publish [OPTIONS]`

Expand All @@ -327,6 +329,19 @@ Publish the current package



## `moon package`

Package the current module

**Usage:** `moon package [OPTIONS]`

###### **Options:**

* `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date
* `--list`



## `moon update`

Update the package registry index
Expand Down
19 changes: 17 additions & 2 deletions docs/manual/src/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This document contains the help content for the `moon` command-line program.
* [`moon login`](#moon-login)
* [`moon register`](#moon-register)
* [`moon publish`](#moon-publish)
* [`moon package`](#moon-package)
* [`moon update`](#moon-update)
* [`moon coverage`](#moon-coverage)
* [`moon coverage report`](#moon-coverage-report)
Expand Down Expand Up @@ -51,7 +52,8 @@ This document contains the help content for the `moon` command-line program.
* `tree` — Display the dependency tree
* `login` — Log in to your account
* `register` — Register an account at mooncakes.io
* `publish` — Publish the current package
* `publish` — Publish the current module
* `package` — Package the current module
* `update` — Update the package registry index
* `coverage` — Code coverage utilities
* `generate-build-matrix` — Generate build matrix for benchmarking (legacy feature)
Expand Down Expand Up @@ -317,7 +319,7 @@ Register an account at mooncakes.io

## `moon publish`

Publish the current package
Publish the current module

**Usage:** `moon publish [OPTIONS]`

Expand All @@ -327,6 +329,19 @@ Publish the current package



## `moon package`

Package the current module

**Usage:** `moon package [OPTIONS]`

###### **Options:**

* `--frozen` — Do not sync dependencies, assuming local dependencies are up-to-date
* `--list`



## `moon update`

Update the package registry index
Expand Down

0 comments on commit e7d1728

Please sign in to comment.