3 files changed, +15, -5
f70b8d3Add -O flag as fallback owner
author
mogi <git@paramogi.world> on 18-11-2026 15:18 UTC
committer
mogi <git@paramogi.world> on 18-11-2026 15:18 UTC
parent42463a9
+1, -1
    @@ -12,7 +12,7 @@ pub enum WitError {
1212 impl fmt::Display for WitError {
1313     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1414         match self {
15  -            WitError::Usage => write!(f, "usage: wit -o outdir repo.git..."),
  15+            WitError::Usage => write!(f, "usage: wit [-O owner] -o outdir repo.git..."),
1616             WitError::InvalidDate => write!(f, "invalid commit date"),
1717             WitError::Git(e) => write!(f, "{}", e.message()),
1818             WitError::Io(e) => write!(f, "{e}"),
+9, -2
    @@ -9,6 +9,7 @@ use std::{env, fs, path::PathBuf, process};
 9 9 use crate::error::WitError;
1010 
1111 struct Args {
  12+    owner: Option<String>,
1213     out_dir: PathBuf,
1314     repos: Vec<String>,
1415 }
    @@ -21,11 +22,13 @@ fn main() {
2122 }
2223 
2324 fn parse_args() -> Result<Args, WitError> {
  25+    let mut owner = None;
2426     let mut out_dir = None;
2527     let mut repos = Vec::new();
2628     let mut args = env::args().skip(1);
2729     while let Some(arg) = args.next() {
2830         match arg.as_str() {
  31+            "-O" => owner = Some(args.next().ok_or(WitError::Usage)?),
2932             "-o" => out_dir = Some(PathBuf::from(args.next().ok_or(WitError::Usage)?)),
3033             s if s.starts_with('-') => return Err(WitError::Usage),
3134             _ => repos.push(arg),
    @@ -35,13 +38,17 @@ fn parse_args() -> Result<Args, WitError> {
3538     if repos.is_empty() {
3639         return Err(WitError::Usage);
3740     }
38  -    Ok(Args { out_dir, repos })
  41+    Ok(Args {
  42+        owner,
  43+        out_dir,
  44+        repos,
  45+    })
3946 }
4047 
4148 fn run() -> Result<(), WitError> {
4249     let args = parse_args()?;
4350     for path in &args.repos {
44  -        let repo = RepoInfo::open(path)?;
  51+        let repo = RepoInfo::open(path, args.owner.as_deref())?;
4552         let page = gen_page(&repo)?;
4653         let repo_dir = args.out_dir.join(&repo.name);
4754         fs::create_dir_all(&repo_dir)?;
    @@ -39,7 +39,7 @@ impl RepoInfo {
3939         }
4040     }
4141 
42  -    pub fn open(path: &str) -> Result<Self, WitError> {
  42+    pub fn open(path: &str, default_owner: Option<&str>) -> Result<Self, WitError> {
4343         let repo = Repository::open_bare(path)?;
4444         let repo_path = repo.path();
4545         let name = repo_path
    @@ -49,7 +49,10 @@ impl RepoInfo {
4949             .unwrap_or_default();
5050         let name = name.strip_suffix(".git").unwrap_or(name).to_string();
5151         let description = Self::read_optional_file(repo_path, "description")?;
52  -        let owner = Self::read_optional_file(repo_path, "owner")?;
  52+        let mut owner = Self::read_optional_file(repo_path, "owner")?;
  53+        if owner.is_empty() {
  54+            owner = default_owner.unwrap_or_default().to_string();
  55+        }
5356         let commit_list = Self::handle_commits(&repo)?;
5457         Ok(Self::new(name, description, owner, commit_list))
5558     }