Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions cli/src/commands/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ use engine::handlers::add::AddRequest;
/// - **`--update, -u`**: Add modified and deleted files only. Conflicts with `--all`.
/// - **`--dry-run, -n`**: Show which files *would* be added, without actually staging them.
/// - **`--verbose, -v`**: Increase verbosity of output.
#[derive(Default)]
pub struct AddCommand;

impl AddCommand {
/// Creates a new instance of the `AddCommand`.
pub fn new() -> Self {
Self
}

/// Path argument key.
const ARG_PATH: &'static str = "path";

Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ use miette::{IntoDiagnostic, Result};
/// Allows listing, creating, deleting, and renaming branches within the repository.
/// It handles argument parsing to dispatch the appropriate request (Create, Delete,
/// Rename, or List) to the [`BranchHandler`].
#[derive(Default)]
pub struct BranchCommand;

impl BranchCommand {
/// Creates a new instance of the [`BranchCommand`].
pub fn new() -> Self {
Self
}

/// First positional argument: branch name (creation/deletion) or old branch name (renaming).
const ARG_NAME: &'static str = "branch-name";

Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ use url::Url;
/// Clones a remote repository into a new directory, creates a
/// tracking connection to the remote repository (origin), and checks out
/// the default branch.
#[derive(Default)]
pub struct CloneCommand;

impl CloneCommand {
/// Creates a new instance of the [`CloneCommand`].
pub fn new() -> Self {
Self {}
}

/// Argument name for specifying the remote repository URL.
const ARG_REPOSITORY: &'static str = "repository";

Expand Down
6 changes: 1 addition & 5 deletions cli/src/commands/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ use owo_colors::OwoColorize;
/// along with a user-supplied message and optional metadata (author, date, etc.).
/// Supports automatically staging changes, amending the last commit, or performing a dry run
/// to preview the commit without persisting it.
#[derive(Default)]
pub struct CommitCommand;

impl CommitCommand {
/// Creates a new instance of the `CommitCommand`.
pub fn new() -> Self {
Self
}

/// Argument key for specifying the commit message.
/// Corresponds to the `-m, --message <MESSAGE>` option.
const ARG_MESSAGE: &'static str = "message";
Expand Down
11 changes: 3 additions & 8 deletions cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ use subcommands::*;
///
/// Serves as a namespace for configuration-related subcommands:
/// list, get, set, unset, and edit settings at global/local/file scopes.
#[derive(Default)]
pub struct ConfigCommand;

impl ConfigCommand {
/// Creates a new instance of the `ConfigCommand`.
pub fn new() -> Self {
Self
}
}

#[async_trait]
impl MevaCommand for ConfigCommand {
type Container = MevaContainer;
Expand All @@ -47,6 +41,7 @@ impl MevaCommand for ConfigCommand {
Box::new(ConfigSetCommand),
Box::new(ConfigUnsetCommand),
Box::new(ConfigEditCommand),
Box::new(ConfigCreateCommand),
]
}

Expand All @@ -63,7 +58,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = ConfigCommand::new();
let cmd = ConfigCommand;
assert_eq!(cmd.name(), "config");
assert_eq!(
cmd.about(),
Expand Down
2 changes: 2 additions & 0 deletions cli/src/commands/config/subcommands.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
pub mod create;
pub mod edit;
pub mod get;
pub mod list;
pub mod set;
pub mod unset;

pub use create::ConfigCreateCommand;
pub use edit::ConfigEditCommand;
pub use get::ConfigGetCommand;
pub use list::ConfigListCommand;
Expand Down
70 changes: 70 additions & 0 deletions cli/src/commands/config/subcommands/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::path::PathBuf;

use async_trait::async_trait;
use clap::{ArgMatches, Command};
use engine::EngineContainer;
use engine::engine_container::MevaContainer;
use engine::handlers::config::CreateRequest;
use miette::IntoDiagnostic;

use crate::commands::MevaCommand;
use crate::extensions::WithFile;

/// Implements the `create` subcommand for Meva configuration management.
///
/// Creates a new configuration file at the specified path or the default global location.
#[derive(Default)]
pub struct ConfigCreateCommand;

#[async_trait]
impl MevaCommand for ConfigCreateCommand {
type Container = MevaContainer;

fn name(&self) -> &'static str {
"create"
}

fn about(&self) -> &'static str {
"Create a new configuration file"
}

fn version(&self) -> &'static str {
"1.0.0"
}

fn build_command(&self) -> Command {
self.build_base_command()
.with_file_arg("Path to the configuration file to create")
}

async fn execute(
&self,
matches: &ArgMatches,
container: &Self::Container,
) -> miette::Result<()> {
let file = matches.get_one::<PathBuf>(Command::ARG_FILE);

let request = CreateRequest {
file: file.cloned(),
};

let config_handler = container.config_handler().into_diagnostic()?;
config_handler.handle_create(request).into_diagnostic()?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use rstest::rstest;

#[rstest]
fn test_command_name_about_version() {
let cmd = ConfigCreateCommand;
assert_eq!(cmd.name(), "create");
assert_eq!(cmd.about(), "Create a new configuration file");
assert_eq!(cmd.version(), "1.0.0");
}
}
11 changes: 2 additions & 9 deletions cli/src/commands/config/subcommands/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@ use crate::extensions::{LocationSelection, WithLocations};
///
/// Opens the chosen configuration file in the user's preferred editor,
/// respecting any `core.editor` override in config or falling back to OS defaults.
#[derive(Default)]
pub struct ConfigEditCommand;

impl ConfigEditCommand {
/// Creates a new instance of the `ConfigGetCommand`.
#[allow(dead_code)]
pub fn new() -> Self {
Self
}
}

#[async_trait]
impl MevaCommand for ConfigEditCommand {
type Container = MevaContainer;
Expand Down Expand Up @@ -75,7 +68,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = ConfigEditCommand::new();
let cmd = ConfigEditCommand;
assert_eq!(cmd.name(), "edit");
assert_eq!(cmd.about(), "Open the config file in your default editor");
assert_eq!(cmd.version(), "1.0.0");
Expand Down
9 changes: 2 additions & 7 deletions cli/src/commands/config/subcommands/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ use miette::IntoDiagnostic;
use crate::commands::MevaCommand;
use crate::extensions::{LocationSelection, WithLocations};

#[derive(Default)]
pub struct ConfigGetCommand;

/// Implements the `get` subcommand for Meva configuration management.
///
/// Retrieves the value of a specified TOML key from the chosen
/// configuration scope, with an optional default fallback if the key is missing.
impl ConfigGetCommand {
/// Creates a new instance of the `ConfigGetCommand`.
#[allow(dead_code)]
pub fn new() -> Self {
Self
}

const ARG_KEY: &'static str = "key";

const ARG_DEFAULT: &'static str = "default";
Expand Down Expand Up @@ -101,7 +96,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = ConfigGetCommand::new();
let cmd = ConfigGetCommand;
assert_eq!(cmd.name(), "get");
assert_eq!(cmd.about(), "Get the value for a given configuration key");
assert_eq!(cmd.version(), "1.0.0");
Expand Down
11 changes: 2 additions & 9 deletions cli/src/commands/config/subcommands/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ use crate::extensions::{LocationSelection, WithLocations};
///
/// Retrieves and displays all key/value pairs from the selected
/// configuration scope.
#[derive(Default)]
pub struct ConfigListCommand;

impl ConfigListCommand {
/// Creates a new instance of the `ConfigListCommand`.
#[allow(dead_code)]
pub fn new() -> Self {
Self
}
}

#[async_trait]
impl MevaCommand for ConfigListCommand {
type Container = MevaContainer;
Expand Down Expand Up @@ -95,7 +88,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = ConfigListCommand::new();
let cmd = ConfigListCommand;
assert_eq!(cmd.name(), "list");
assert_eq!(cmd.about(), "Print all available configuration entries");
assert_eq!(cmd.version(), "1.0.0");
Expand Down
9 changes: 2 additions & 7 deletions cli/src/commands/config/subcommands/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ use crate::extensions::{LocationSelection, WithKey, WithLocations};
///
/// Adds or updates a specified TOML key in the chosen configuration scope
/// with a provided value.
#[derive(Default)]
pub struct ConfigSetCommand;

impl ConfigSetCommand {
/// Creates a new instance of the `ConfigSetCommand`.
#[allow(dead_code)]
pub fn new() -> Self {
Self
}

const ARG_VALUE: &'static str = "value";
}

Expand Down Expand Up @@ -99,7 +94,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = ConfigSetCommand::new();
let cmd = ConfigSetCommand;
assert_eq!(cmd.name(), "set");
assert_eq!(cmd.about(), "Set the value for a given configuration key");
assert_eq!(cmd.version(), "1.0.0");
Expand Down
11 changes: 2 additions & 9 deletions cli/src/commands/config/subcommands/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,9 @@ use crate::extensions::{LocationSelection, WithKey, WithLocations};
/// Implements the `unset` subcommand for Meva configuration management.
///
/// Removes a specified TOML key from the chosen configuration scope.
#[derive(Default)]
pub struct ConfigUnsetCommand;

impl ConfigUnsetCommand {
/// Creates a new instance of the `ConfigUnsetCommand`.
#[allow(dead_code)]
pub fn new() -> Self {
Self
}
}

#[async_trait]
impl MevaCommand for ConfigUnsetCommand {
type Container = MevaContainer;
Expand Down Expand Up @@ -81,7 +74,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = ConfigUnsetCommand::new();
let cmd = ConfigUnsetCommand;
assert_eq!(cmd.name(), "unset");
assert_eq!(cmd.about(), "Remove a configuration entry");
assert_eq!(cmd.version(), "1.0.0");
Expand Down
8 changes: 2 additions & 6 deletions cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ use crate::commands::MevaCommand;
/// Implements the `diff` command for Meva DVCS.
///
/// Shows changes between commits, the index, and the working tree.
#[derive(Default)]
pub struct DiffCommand;

impl DiffCommand {
/// Creates a new instance of the `DiffCommand`.
pub fn new() -> Self {
Self {}
}

/// Argument name for the `--cached` flag.
/// When set, the command compares the index to the specified commit (default: HEAD).
const ARG_CACHED: &'static str = "cached";
Expand Down Expand Up @@ -185,7 +181,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = DiffCommand::new();
let cmd = DiffCommand;
assert_eq!(cmd.name(), "diff");
assert_eq!(
cmd.about(),
Expand Down
8 changes: 2 additions & 6 deletions cli/src/commands/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ use crate::{commands::MevaCommand, extensions::WithVerbose};
/// This command is responsible for downloading objects and references from a remote
/// repository. It serves as the entry point for the fetch logic, handling argument
/// parsing and delegating the execution to the appropriate engine handler.
#[derive(Default)]
pub struct FetchCommand;

impl FetchCommand {
/// Creates a new instance of the [`FetchCommand`].
pub fn new() -> Self {
Self {}
}

/// The name of the argument used to specify the prune flag.
const ARG_PRUNE: &'static str = "prune";

Expand Down Expand Up @@ -106,7 +102,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = FetchCommand::new();
let cmd = FetchCommand;
assert_eq!(cmd.name(), "fetch");
assert_eq!(
cmd.about(),
Expand Down
10 changes: 2 additions & 8 deletions cli/src/commands/ignore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ use subcommands::*;
///
/// Serves as a namespace for subcommands managing ignore patterns:
/// add, remove, check, and edit ignore rules for files and directories.
#[derive(Default)]
pub struct IgnoreCommand;

impl IgnoreCommand {
/// Creates a new instance of the `IgnoreCommand`.
pub fn new() -> Self {
Self
}
}

#[async_trait]
impl MevaCommand for IgnoreCommand {
type Container = MevaContainer;
Expand Down Expand Up @@ -62,7 +56,7 @@ mod tests {

#[rstest]
fn test_command_name_about_version() {
let cmd = IgnoreCommand::new();
let cmd = IgnoreCommand;
assert_eq!(cmd.name(), "ignore");
assert_eq!(
cmd.about(),
Expand Down
Loading