Skip to content

Commit bef5f0b

Browse files
committed
Improved documentation across the tool
Signed-off-by: Adam Poulemanos <[email protected]>
1 parent c0b00ec commit bef5f0b

File tree

7 files changed

+188
-34
lines changed

7 files changed

+188
-34
lines changed

.roomodes

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"customModes": [
3+
{
4+
"slug": "plain-docs-writer",
5+
"name": "📝 Plain Documentation Writer",
6+
"roleDefinition": "You are a technical documentation expert. You specialize in creating clear and developer-friendly documentation for software projects. Your role includes: (1) Writing clear, concise technical documentation. (2) Creating and maintaining README files, API documentation, and user guides. (3) Following documentation best practices and style guides. (4) Using your deep understanding of software development to explain complex concepts simply. (5) Organizing documentation in a logical, easily navigable structure.",
7+
"whenToUse": "Use this mode for writing or editing documentation.",
8+
"customInstructions": "Focus on creating documentation that is clear, concise, and follows a consistent style. Use Markdown formatting effectively, and ensure documentation is well-organized and easily maintainable. Don't over-document. If a function or feature is well-typed and self-explanatory, a sentence may suffice. Use plain language, avoid jargon and idioms, and ensure that the documentation is accessible to developers of all skill levels. Always use active voice and present tense -- instead of \"The function adds two numbers,\" write \"Adds two numbers.\"\n\n If you see 'to-do' like comments that aren't marked as TODO, rewrite them as `TODO:`s that are actionable and clear.",
9+
"groups": [
10+
"read",
11+
"edit",
12+
"browser"
13+
]
14+
}
15+
]
16+
}

custom_modes.json

Whitespace-only changes.

src/commands.rs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,93 @@
1+
#![doc = r#"
2+
Command-line argument definitions for the `submod` tool.
3+
4+
Defines the CLI structure and subcommands using [`clap`] for managing git submodules with sparse checkout support.
5+
6+
# Overview
7+
8+
- Parses CLI arguments for the `submod` binary.
9+
- Supports commands for adding, checking, initializing, updating, resetting, and syncing submodules.
10+
- Allows specifying a custom configuration file (default: `submod.toml`).
11+
12+
# Commands
13+
14+
- [`Commands::Add`](src/commands.rs): Adds a new submodule configuration.
15+
- [`Commands::Check`](src/commands.rs): Checks submodule status and configuration.
16+
- [`Commands::Init`](src/commands.rs): Initializes missing submodules.
17+
- [`Commands::Update`](src/commands.rs): Updates all submodules.
18+
- [`Commands::Reset`](src/commands.rs): Hard resets submodules (stash, reset --hard, clean).
19+
- [`Commands::Sync`](src/commands.rs): Runs a full sync (check, init, update).
20+
21+
# Usage Example
22+
23+
```sh
24+
submod add my-lib libs/my-lib https://github.com/example/my-lib.git --sparse-paths "src/,include/" --settings "ignore=all"
25+
submod check
26+
submod init
27+
submod update
28+
submod reset --all
29+
submod sync
30+
```
31+
32+
# Configuration
33+
34+
Use the `--config` option to specify a custom config file.
35+
36+
See the [README.md](../README.md) for full usage and configuration details.
37+
"#]
38+
139
use clap::{Parser, Subcommand};
240
use std::path::PathBuf;
341

42+
/// Top-level CLI parser for the `submod` tool.
43+
///
44+
/// Accepts a subcommand and an optional config file path.
445
#[derive(Parser)]
546
#[command(name = "submod")]
647
#[command(about = "Manage git submodules with sparse checkout support")]
748
pub struct Cli {
49+
/// Subcommand to execute.
850
#[command(subcommand)]
951
pub command: Commands,
1052

53+
/// Path to the configuration file (default: submod.toml).
1154
#[arg(short, long, default_value = "submod.toml")]
1255
pub config: PathBuf,
1356
}
1457

58+
/// Supported subcommands for the `submod` tool.
1559
#[derive(Subcommand)]
1660
pub enum Commands {
17-
/// Add a new submodule configuration
61+
/// Adds a new submodule configuration.
1862
Add {
19-
/// Submodule name
63+
/// Submodule name.
2064
name: String,
21-
/// Local path for the submodule
65+
/// Local path for the submodule.
2266
path: String,
23-
/// Git repository URL
67+
/// Git repository URL.
2468
url: String,
25-
/// Sparse checkout paths (comma-separated)
69+
/// Sparse checkout paths (comma-separated).
2670
#[arg(short, long)]
2771
sparse_paths: Option<String>,
28-
/// Git settings like "ignore=all"
72+
/// Additional git settings (e.g., "ignore=all").
2973
#[arg(short = 'S', long)]
3074
settings: Option<String>,
3175
},
32-
/// Check submodule status and configuration
76+
/// Checks submodule status and configuration.
3377
Check,
34-
/// Initialize missing submodules
78+
/// Initializes missing submodules.
3579
Init,
36-
/// Update all submodules
80+
/// Updates all submodules.
3781
Update,
38-
/// Hard reset submodules (stash, reset --hard, clean)
82+
/// Hard resets submodules (stash, reset --hard, clean).
3983
Reset {
40-
/// Reset all submodules
84+
/// Reset all submodules.
4185
#[arg(short, long)]
4286
all: bool,
43-
/// Specific submodule names to reset
87+
/// Specific submodule names to reset.
4488
#[arg(required_unless_present = "all")]
4589
names: Vec<String>,
4690
},
47-
/// Run full sync: check, init, update
91+
/// Runs a full sync: check, init, update.
4892
Sync,
4993
}

src/config.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
#![doc = r#"
2+
Configuration types and utilities for submod.
3+
4+
Defines serializable wrappers for git submodule options, project-level defaults, and submodule
5+
configuration management. Supports loading and saving configuration in TOML format.
6+
7+
Main Types:
8+
- SerializableIgnore, SerializableFetchRecurse, SerializableBranch, SerializableUpdate: Wrappers for git submodule config enums, supporting (de)serialization.
9+
- SubmoduleGitOptions: Git-specific options for a submodule.
10+
- SubmoduleDefaults: Project-level default submodule options.
11+
- SubmoduleConfig: Configuration for a single submodule.
12+
- Config: Main configuration structure, containing defaults and all submodules.
13+
14+
Features:
15+
- Load and save configuration from/to TOML files.
16+
- Serialize/deserialize submodule options for config files.
17+
- Manage submodule entries and defaults programmatically.
18+
19+
TODO:
20+
- Add validation for config values when loading from file.
21+
"#]
22+
123
use anyhow::{Context, Result};
224
use bstr::BStr;
325
use gix_submodule::config::{Branch, FetchRecurse, Ignore, Update};
@@ -6,9 +28,7 @@ use std::fs;
628
use std::{collections::HashMap, path::Path};
729
use toml_edit::{Array, DocumentMut, Item, Table, value};
830

9-
/**========================================================================
10-
** Wrappers for Gix Submodule Config
11-
*========================================================================**/
31+
1232
/// Serializable wrapper for [`Ignore`] config
1333
#[derive(Debug, Default, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash)]
1434
pub struct SerializableIgnore(pub Ignore);
@@ -221,7 +241,6 @@ impl From<SerializableUpdate> for Update {
221241
}
222242

223243
/// Git options for a submodule
224-
/// Git-specific options for submodule configuration
225244
#[derive(Debug, Default, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)]
226245
pub struct SubmoduleGitOptions {
227246
/// How to handle dirty files when updating submodules

src/gitoxide_manager.rs

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,48 @@
1-
//! Gitoxide-maximized submodule manager
2-
//!
3-
//! This module implements the submodule manager with maximum use of gitoxide/gix APIs
4-
//! and strategic fallbacks only where necessary.
1+
#![doc = r#"
2+
# Gitoxide-Based Submodule Manager
3+
4+
Provides core logic for managing git submodules using the [`gitoxide`](https://github.com/Byron/gitoxide) library, with fallbacks to `git2` and the Git CLI when needed. Supports advanced features like sparse checkout and TOML-based configuration.
5+
6+
## Overview
7+
8+
- Loads submodule configuration from a TOML file.
9+
- Adds, initializes, updates, resets, and checks submodules.
10+
- Uses `gitoxide` APIs where possible for performance and reliability.
11+
- Falls back to `git2` (if enabled) or the Git CLI for unsupported operations.
12+
- Supports sparse checkout configuration per submodule.
13+
14+
## Key Types
15+
16+
- [`SubmoduleError`](src/gitoxide_manager.rs:14): Error type for submodule operations.
17+
- [`SubmoduleStatus`](src/gitoxide_manager.rs:55): Reports the status of a submodule, including cleanliness, commit, remotes, and sparse checkout state.
18+
- [`SparseStatus`](src/gitoxide_manager.rs:77): Describes the sparse checkout configuration state.
19+
- [`GitoxideSubmoduleManager`](src/gitoxide_manager.rs:94): Main struct for submodule management.
20+
21+
## Main Operations
22+
23+
- [`GitoxideSubmoduleManager::add_submodule()`](src/gitoxide_manager.rs:207): Adds a new submodule, configuring sparse checkout if specified.
24+
- [`GitoxideSubmoduleManager::init_submodule()`](src/gitoxide_manager.rs:643): Initializes a submodule, adding it if missing.
25+
- [`GitoxideSubmoduleManager::update_submodule()`](src/gitoxide_manager.rs:544): Updates a submodule using the Git CLI.
26+
- [`GitoxideSubmoduleManager::reset_submodule()`](src/gitoxide_manager.rs:574): Resets a submodule (stash, hard reset, clean).
27+
- [`GitoxideSubmoduleManager::check_all_submodules()`](src/gitoxide_manager.rs:732): Checks the status of all configured submodules.
28+
29+
## Sparse Checkout Support
30+
31+
- Checks and configures sparse checkout for each submodule based on the TOML config.
32+
- Writes sparse-checkout patterns and applies them using the Git CLI.
33+
34+
## Error Handling
35+
36+
All operations return [`SubmoduleError`](src/gitoxide_manager.rs:14) for consistent error reporting.
37+
38+
## TODOs
39+
40+
- TODO: Implement submodule addition using gitoxide APIs when available ([`add_submodule_with_gix`](src/gitoxide_manager.rs:278)).
41+
42+
## Usage
43+
44+
Use this module as the backend for CLI commands to manage submodules in a repository. See the project [README](README.md) for usage examples and configuration details.
45+
"#]
546

647
use crate::config::{Config, SubmoduleConfig, SubmoduleGitOptions};
748
use gix::Repository;
@@ -38,11 +79,11 @@ pub enum SubmoduleError {
3879

3980
/// Submodule not found in repository
4081
#[error("Submodule {name} not found")]
41-
SubmoduleNotFound { name: String },
82+
SubmoduleNotFound {
83+
/// Name of the missing submodule.
84+
name: String,
85+
},
4286

43-
/// Sparse checkout configuration error
44-
#[error("Invalid sparse checkout configuration: {reason}")]
45-
SparseCheckoutError { reason: String },
4687

4788
/// Repository access or validation error
4889
#[error("Repository not found or invalid")]
@@ -101,6 +142,16 @@ pub struct GitoxideSubmoduleManager {
101142
}
102143

103144
impl GitoxideSubmoduleManager {
145+
/// Creates a new `GitoxideSubmoduleManager` by loading configuration from the given path.
146+
///
147+
/// # Arguments
148+
///
149+
/// * `config_path` - Path to the TOML configuration file.
150+
///
151+
/// # Errors
152+
///
153+
/// Returns `SubmoduleError::RepositoryError` if the repository cannot be discovered,
154+
/// or `SubmoduleError::ConfigError` if the configuration fails to load.
104155
pub fn new(config_path: PathBuf) -> Result<Self, SubmoduleError> {
105156
// Use gix::discover for repository detection
106157
let repo = gix::discover(".").map_err(|_| SubmoduleError::RepositoryError)?;

src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
//! Submod - Git submodule manager with sparse checkout support using gitoxide
1+
//! Library entry point for submod, a Git submodule manager with sparse checkout support.
22
//!
3-
//! This library exists only for testing purposes. We're a CLI tool, not a library.
4-
//! You're welcome to use it as a library, but we don't guarantee any API stability.
3+
//! This crate is primarily intended for CLI use. The library API is not stable and may change.
4+
//!
5+
//! # Modules
6+
//! - [`config`]: Submodule configuration management.
7+
//! - [`gitoxide_manager`]: Implementation of submodule operations using gitoxide.
8+
//!
9+
//! # Exports
10+
//! - Common types and managers for use in tests or advanced integrations.
11+
//!
12+
//! # Version
13+
//! - Exposes the current crate version as [`VERSION`].
14+
//!
15+
//! # Note
16+
//! The API is not guaranteed to be stable. Use at your own risk.
517
618
/// Configuration management for submodules
719
pub mod config;

src/main.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
//! Submod - Git submodule manager with sparse checkout support
2-
//!
3-
//! A CLI tool for managing Git submodules with advanced features like sparse checkout
4-
//! support using the gitoxide library for high performance operations.
1+
#![doc = r#"
2+
Main entry point for the submod CLI tool.
3+
4+
Parses command-line arguments and dispatches submodule management commands using the
5+
[`GitoxideSubmoduleManager`]. Supports adding, checking, initializing, updating, resetting,
6+
and syncing submodules with advanced features like sparse checkout.
7+
8+
# Commands
9+
10+
- `add`: Add a new submodule with optional sparse paths.
11+
- `check`: Check the status of all configured submodules.
12+
- `init`: Initialize all submodules from config.
13+
- `update`: Update all submodules.
14+
- `reset`: Reset specified or all submodules.
15+
- `sync`: Run check, init, and update in sequence.
16+
17+
Exits with an error if any operation fails.
18+
"#]
519

620
mod commands;
721
mod config;
@@ -12,8 +26,6 @@ use crate::gitoxide_manager::GitoxideSubmoduleManager;
1226
use anyhow::Result;
1327
use clap::Parser;
1428

15-
// Old SubmoduleManager removed - now using GitoxideSubmoduleManager
16-
1729
fn main() -> Result<()> {
1830
let cli = Cli::parse();
1931

0 commit comments

Comments
 (0)