fj/src/cli/mod.rs
Stephen Way 191d941c78
expand: repo auto-detect, --web, editor, PR diff/checks/ready/review/status, repo lifecycle, api headers/paginate
* CI: pre-push hook (fmt, clippy -D warnings, test, release build) plus
  opt-in FJ_E2E=1 smoke. Install via scripts/install-hooks.sh.
* Repo auto-detection from git remote: -R/--repo becomes optional on all
  repo-scoped subcommands. Detection prefers `upstream` then `origin`,
  honors --host, and parses https/ssh/scp-style URLs.
* `--web` flag wired to every list/view command (open in default browser).
* `$EDITOR` integration for issue/pr create + comment + edit (omit
  `--body` to launch your editor; `-` keeps stdin).
* PR: new `diff`, `commits`, `files`, `checks`, `ready`, `review`,
  `edit`, `status`, `reopen` subcommands. `view --comments` now shows
  reviews too.
* Issue: `edit` and `develop` (creates a branch for the issue).
* Repo: `fork`, `sync`, `edit`, `rename`, `archive`, `unarchive`,
  `delete` (with slug-confirmation), `branches`, `topics`.
* `fj api` gains `-H` headers, `--paginate` (follows Link rel=next),
  `--include` (response headers), `--silent`. The jq-ish projector now
  supports `[N]`/`[-N]` brackets and `|` pipes.
* MSRV bumped to 1.82 (uses `is_none_or`).
* 46 unit tests covering pure logic: hosts CRUD, remote URL parsing,
  link header parser, jq projection, branch label fallback, slugify.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 08:22:40 -07:00

71 lines
1.9 KiB
Rust

pub mod api;
pub mod auth;
pub mod context;
pub mod editor;
pub mod issue;
pub mod pr;
pub mod repo;
pub mod web;
use anyhow::Result;
use clap::{Parser, Subcommand};
/// `fj` — command-line tool for Forgejo.
#[derive(Debug, Parser)]
#[command(
name = "fj",
version,
about = "Command-line tool for Forgejo",
long_about = None,
propagate_version = true,
arg_required_else_help = true,
)]
pub struct Cli {
/// Override the host for this command (otherwise the current host from
/// `fj auth login` is used).
#[arg(long, global = true, env = "FJ_HOST")]
pub host: Option<String>,
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Manage authentication against Forgejo hosts.
Auth(auth::AuthCmd),
/// Work with repositories.
Repo(repo::RepoCmd),
/// Work with issues.
Issue(issue::IssueCmd),
/// Work with pull requests.
Pr(pr::PrCmd),
/// Make a raw API request (like `gh api`).
Api(api::ApiArgs),
/// Print shell completions to stdout.
Completion(CompletionArgs),
}
#[derive(Debug, clap::Args)]
pub struct CompletionArgs {
/// Shell to generate completions for.
#[arg(value_enum)]
pub shell: clap_complete::Shell,
}
pub async fn run(cli: Cli) -> Result<()> {
match cli.command {
Command::Auth(cmd) => auth::run(cmd).await,
Command::Repo(cmd) => repo::run(cmd, cli.host.as_deref()).await,
Command::Issue(cmd) => issue::run(cmd, cli.host.as_deref()).await,
Command::Pr(cmd) => pr::run(cmd, cli.host.as_deref()).await,
Command::Api(args) => api::run(args, cli.host.as_deref()).await,
Command::Completion(args) => {
use clap::CommandFactory;
let mut cmd = Cli::command();
clap_complete::generate(args.shell, &mut cmd, "fj", &mut std::io::stdout());
Ok(())
}
}
}