2023-06-09 16:09:32 +02:00
|
|
|
// A Rust GitOps/symlinkfarm orchestrator inspired by GNU Stow.
|
|
|
|
// Copyright (C) 2023 Christina Sørensen <christina@cafkafk.com>
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see https://www.gnu.org/gpl-3.0.html.
|
2023-07-01 10:40:45 +02:00
|
|
|
//
|
|
|
|
//! Handles command line input
|
2023-06-09 16:09:32 +02:00
|
|
|
|
2023-06-08 18:50:09 +02:00
|
|
|
use crate::utils::dir::home_dir;
|
2023-06-09 18:28:19 +02:00
|
|
|
use crate::utils::strings::INTERACTIVE_NOTICE;
|
2023-06-08 18:50:09 +02:00
|
|
|
|
|
|
|
use clap::{ArgAction, CommandFactory, Parser, Subcommand};
|
|
|
|
|
|
|
|
const CONFIG_FILE: &str = "/.config/gg/config.yaml";
|
|
|
|
|
2023-06-09 18:28:19 +02:00
|
|
|
const HELP_TEMPLATE: &str = "\
|
|
|
|
{before-help}{name} {version}
|
|
|
|
{author-with-newline}{about-with-newline}
|
|
|
|
{usage-heading} {usage}
|
|
|
|
|
|
|
|
{all-args}{after-help}
|
|
|
|
|
|
|
|
";
|
|
|
|
|
2023-06-08 18:50:09 +02:00
|
|
|
//#[clap(author, version, about, long_about = None)]
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
#[clap(
|
|
|
|
name="gg - git gut",
|
|
|
|
author,
|
|
|
|
version,
|
|
|
|
long_version=env!("CARGO_PKG_VERSION"),
|
|
|
|
about="GitOps for the masses",
|
|
|
|
long_about="A Rust GitOps and linkfarm orchestrator inspired by GNU Stow",
|
2023-06-09 18:16:28 +02:00
|
|
|
subcommand_required=false,
|
2023-06-08 18:50:09 +02:00
|
|
|
arg_required_else_help=true,
|
2023-06-09 18:28:19 +02:00
|
|
|
help_template=HELP_TEMPLATE.to_owned()+INTERACTIVE_NOTICE,
|
2023-06-08 18:50:09 +02:00
|
|
|
)]
|
|
|
|
pub struct Args {
|
|
|
|
/// The config file to use
|
|
|
|
#[allow(deprecated)] // NOTE we don't care about windows , we don't support it
|
|
|
|
#[arg(short, long, default_value_t = home_dir() + CONFIG_FILE)]
|
|
|
|
pub config: String,
|
|
|
|
|
2023-06-09 16:24:04 +02:00
|
|
|
/// Print license information
|
2023-06-08 18:50:09 +02:00
|
|
|
#[arg(long)]
|
|
|
|
pub license: bool,
|
|
|
|
|
2023-06-09 16:24:04 +02:00
|
|
|
/// Print warranty information
|
|
|
|
#[arg(long)]
|
|
|
|
pub warranty: bool,
|
|
|
|
|
2023-07-03 11:16:43 +02:00
|
|
|
/// Print code-of-conduct information
|
2023-06-08 18:50:09 +02:00
|
|
|
#[arg(long)]
|
|
|
|
pub code_of_conduct: bool,
|
|
|
|
|
2023-07-03 11:16:43 +02:00
|
|
|
/// Try to be as quiet as possible (unix philosophy) (not imlemented)
|
|
|
|
#[arg(short, long)]
|
|
|
|
pub quiet: bool,
|
|
|
|
|
2023-07-03 11:36:20 +02:00
|
|
|
/// No emoji (not imlemented)
|
|
|
|
#[arg(short, long)]
|
|
|
|
pub no_emoji: bool,
|
|
|
|
|
2023-06-08 18:50:09 +02:00
|
|
|
#[command(subcommand)]
|
2023-06-09 18:16:28 +02:00
|
|
|
pub command: Option<Commands>,
|
2023-06-08 18:50:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
|
|
pub enum Commands {
|
|
|
|
/// Link all... links
|
|
|
|
#[command(visible_alias = "l")]
|
|
|
|
Link { msg: Option<String> },
|
|
|
|
|
|
|
|
/// Do quick pull-commit-push with msg for commit
|
|
|
|
#[command(visible_alias = "q")]
|
|
|
|
Quick { msg: Option<String> },
|
|
|
|
|
2023-07-01 14:57:41 +02:00
|
|
|
/// Do fast pull-commit-push with msg for commit, skipping repo on failure
|
|
|
|
#[command(visible_alias = "f")]
|
|
|
|
Fast { msg: Option<String> },
|
|
|
|
|
2023-06-08 18:50:09 +02:00
|
|
|
/// Clone all repositories
|
|
|
|
#[command(visible_alias = "c")]
|
|
|
|
Clone { msg: Option<String> },
|
|
|
|
|
|
|
|
/// Pull all repositories
|
|
|
|
#[command(visible_alias = "p")]
|
|
|
|
Pull { msg: Option<String> },
|
|
|
|
|
|
|
|
/// Add all files in repositories
|
|
|
|
#[command(visible_alias = "a")]
|
|
|
|
Add { msg: Option<String> },
|
|
|
|
|
|
|
|
/// Perform a git commit in all repositories
|
|
|
|
#[command(visible_alias = "ct")]
|
|
|
|
Commit { msg: Option<String> },
|
|
|
|
|
|
|
|
/// Perform a git commit in all repositories, with predefined message
|
|
|
|
#[command(visible_alias = "m")]
|
|
|
|
CommitMsg { msg: Option<String> },
|
|
|
|
}
|