Rewrites every write-good.Passive hit in the hive-forge clap help text
into terse, imperative, active voice (meaning unchanged) and drops
clap-markdown's own fixed footer ('This document was generated
automatically by...') via MarkdownOptions::show_footer(false), since
that string isn't ours to reword and vale flagged it too.
docs/tools/{hivectl,swarmctl,forge}-cli.md are generated from each
crate's clap tree (see hive-forge/src/main.rs's MarkdownDocs verb) —
regenerated here from the fixed source, not hand-edited.
Refs #4549
78 lines
2.8 KiB
Rust
78 lines
2.8 KiB
Rust
//! `repo-create <name> [--description <d>] [--private] [--default-branch <b>]
|
|
//! [--org <org>] [--auto-init]` — create a forge repository under the current
|
|
//! user (or under `--org`). Prints the new repo's web URL (or the full repo
|
|
//! object under `--json`).
|
|
//!
|
|
//! Wraps `POST /api/v1/user/repos` (or `/orgs/{org}/repos`) so agents don't
|
|
//! reach for raw API calls when the operator greenlights a new repo — the
|
|
//! instance has push-to-create disabled, so `git push` to a non-existent
|
|
//! repo 403s. Pairs with `clone` (then push your content) and
|
|
//! `repo-add-collaborator` (add peers to a fresh agent-namespace repo).
|
|
|
|
use anyhow::Result;
|
|
use clap::Args as ClapArgs;
|
|
use forgejo_api::structs::CreateRepoOption;
|
|
|
|
use crate::client::Client;
|
|
use crate::verbs::print_json;
|
|
|
|
#[derive(ClapArgs)]
|
|
pub struct Args {
|
|
/// Repository name (required). Creates it under the authenticated
|
|
/// user unless you pass `--org`.
|
|
name: String,
|
|
/// Repository description.
|
|
#[arg(long)]
|
|
description: Option<String>,
|
|
/// Create the repo as private (default: public).
|
|
#[arg(long)]
|
|
private: bool,
|
|
/// Default branch name (for example `main`). Only takes effect with `--auto-init`.
|
|
#[arg(long = "default-branch")]
|
|
default_branch: Option<String>,
|
|
/// Create under this organisation instead of your own namespace.
|
|
#[arg(long)]
|
|
org: Option<String>,
|
|
/// Seed an initial commit (README) so you can clone the repo
|
|
/// immediately instead of getting an empty one. Omit to create a
|
|
/// bare repo you push into.
|
|
#[arg(long = "auto-init")]
|
|
auto_init: bool,
|
|
}
|
|
|
|
/// # Errors
|
|
///
|
|
/// Propagates any transport error from the Forgejo REST call (network
|
|
/// unreachable, 4xx/5xx response such as a name clash or insufficient
|
|
/// permission on the target namespace, token missing/invalid) and any
|
|
/// I/O error from writing the result to stdout.
|
|
pub fn run(client: &Client, args: Args) -> Result<()> {
|
|
let payload = CreateRepoOption {
|
|
auto_init: Some(args.auto_init),
|
|
default_branch: args.default_branch,
|
|
description: args.description,
|
|
gitignores: None,
|
|
issue_labels: None,
|
|
license: None,
|
|
name: args.name,
|
|
object_format_name: None,
|
|
private: Some(args.private),
|
|
readme: None,
|
|
template: None,
|
|
trust_model: None,
|
|
};
|
|
|
|
let resp = match args.org.as_deref() {
|
|
Some(org) => client.api().create_org_repo(org, payload).send()?,
|
|
None => client.api().create_current_user_repo(payload).send()?,
|
|
};
|
|
|
|
if client.json_mode() {
|
|
return print_json(&serde_json::to_value(&resp)?);
|
|
}
|
|
// Default human path: print the web URL, like issue create / pr create.
|
|
if let Some(url) = resp.html_url {
|
|
println!("{url}");
|
|
}
|
|
Ok(())
|
|
}
|