diff --git a/Cargo.lock b/Cargo.lock index a3234c1..ef7fb80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,7 +190,7 @@ dependencies = [ [[package]] name = "gg" -version = "0.0.1" +version = "0.0.2" dependencies = [ "clap", "clap_mangen", diff --git a/Cargo.toml b/Cargo.toml index c5ea387..2b9d34c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gg" -version = "0.0.1" +version = "0.0.2" edition = "2021" authors = ["Christina Sørensen "] repository = "https://github.com/cafkafk/gg" diff --git a/src/cli.rs b/src/cli.rs index ad4d77d..b5fa2cc 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,9 +1,35 @@ +// A Rust GitOps/symlinkfarm orchestrator inspired by GNU Stow. +// Copyright (C) 2023 Christina Sørensen +// +// 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. + use crate::utils::dir::home_dir; +use crate::utils::strings::INTERACTIVE_NOTICE; use clap::{ArgAction, CommandFactory, Parser, Subcommand}; const CONFIG_FILE: &str = "/.config/gg/config.yaml"; +const HELP_TEMPLATE: &str = "\ + {before-help}{name} {version} + {author-with-newline}{about-with-newline} + {usage-heading} {usage} + + {all-args}{after-help} + + "; + //#[clap(author, version, about, long_about = None)] #[derive(Parser, Debug)] #[clap( @@ -13,16 +39,9 @@ const CONFIG_FILE: &str = "/.config/gg/config.yaml"; long_version=env!("CARGO_PKG_VERSION"), about="GitOps for the masses", long_about="A Rust GitOps and linkfarm orchestrator inspired by GNU Stow", - subcommand_required=true, + subcommand_required=false, arg_required_else_help=true, - help_template="\ - {before-help}{name} {version} - {author-with-newline}{about-with-newline} - {usage-heading} {usage} - - {all-args}{after-help} - - ", + help_template=HELP_TEMPLATE.to_owned()+INTERACTIVE_NOTICE, )] pub struct Args { /// The config file to use @@ -30,16 +49,20 @@ pub struct Args { #[arg(short, long, default_value_t = home_dir() + CONFIG_FILE)] pub config: String, - /// Print full-text license information + /// Print license information #[arg(long)] pub license: bool, - /// Print full-text code-of-conduct (not implemented) + /// Print warranty information + #[arg(long)] + pub warranty: bool, + + /// Print code-of-conduct information (not implemented) #[arg(long)] pub code_of_conduct: bool, #[command(subcommand)] - pub command: Commands, + pub command: Option, } #[derive(Subcommand, Debug)] diff --git a/src/git.rs b/src/git.rs index 81b0b85..a293bbc 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,3 +1,19 @@ +// A Rust GitOps/symlinkfarm orchestrator inspired by GNU Stow. +// Copyright (C) 2023 Christina Sørensen +// +// 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. + use log::{debug, error, info, trace, warn}; use serde::{Deserialize, Serialize}; use std::os::unix::fs::symlink; @@ -98,7 +114,7 @@ impl GitRepo { /// Pulls the repository if able. fn pull(&self) { let out = Command::new("git") - .current_dir(&(self.path.to_owned() + &self.name)) + .current_dir(format!("{}{}", &self.path, &self.name)) .arg("pull") .status() .expect("failed to pull"); @@ -118,7 +134,7 @@ impl GitRepo { #[allow(dead_code)] fn commit(&self) { let out = Command::new("git") - .current_dir(&(self.path.to_owned() + &self.name)) + .current_dir(format!("{}{}", &self.path, &self.name)) .arg("commit") .status() .expect("failed to commit"); @@ -127,7 +143,7 @@ impl GitRepo { /// Tries to commit changes with a message argument. fn commit_with_msg(&self, msg: &String) { let out = Command::new("git") - .current_dir(&(self.path.to_owned() + &self.name)) + .current_dir(format!("{}{}", &self.path, &self.name)) .arg("commit") .arg("-m") .arg(msg) @@ -138,7 +154,7 @@ impl GitRepo { /// Attempts to push the repository. fn push(&self) { let out = Command::new("git") - .current_dir(&(self.path.to_owned() + &self.name)) + .current_dir(format!("{}{}", &self.path, &self.name)) .arg("push") .status() .expect("failed to push"); diff --git a/src/main.rs b/src/main.rs index 40d252c..4005214 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,19 @@ +// A Rust GitOps/symlinkfarm orchestrator inspired by GNU Stow. +// Copyright (C) 2023 Christina Sørensen +// +// 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. + extern crate log; extern crate pretty_env_logger; @@ -20,33 +36,34 @@ fn main() { let args = Args::parse(); let config = Config::new(&args.config); match &args { - //args if args.quick == true => config.quick(&args.quick), - args if args.license == true => unimplemented!(), + args if args.license == true => println!("{}", utils::strings::INTERACTIVE_LICENSE), + args if args.warranty == true => println!("{}", utils::strings::INTERACTIVE_WARRANTY), args if args.code_of_conduct == true => unimplemented!(), _ => (), } match &args.command { - Commands::Link { msg: _ } => { + Some(Commands::Link { msg: _ }) => { config.link_all(); } - Commands::Quick { msg } => { + Some(Commands::Quick { msg }) => { config.quick(&msg.as_ref().unwrap()); } - Commands::Clone { msg: _ } => { + Some(Commands::Clone { msg: _ }) => { config.clone_all(); } - Commands::Pull { msg: _ } => { + Some(Commands::Pull { msg: _ }) => { config.pull_all(); } - Commands::Add { msg: _ } => { + Some(Commands::Add { msg: _ }) => { config.add_all(); } - Commands::Commit { msg: _ } => { + Some(Commands::Commit { msg: _ }) => { config.commit_all(); } - Commands::CommitMsg { msg } => { + Some(Commands::CommitMsg { msg }) => { config.commit_all_msg(&msg.as_ref().unwrap()); } + None => (), } trace!("{:?}", config); } diff --git a/src/utils.rs b/src/utils.rs index ce3ffca..6c70879 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1 +1,18 @@ +// A Rust GitOps/symlinkfarm orchestrator inspired by GNU Stow. +// Copyright (C) 2023 Christina Sørensen +// +// 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. + pub mod dir; +pub mod strings; diff --git a/src/utils/dir.rs b/src/utils/dir.rs index 14926c1..92c6889 100644 --- a/src/utils/dir.rs +++ b/src/utils/dir.rs @@ -1,3 +1,19 @@ +// A Rust GitOps/symlinkfarm orchestrator inspired by GNU Stow. +// Copyright (C) 2023 Christina Sørensen +// +// 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. + #![feature(stmt_expr_attributes)] use log::{debug, error, info, trace, warn}; diff --git a/src/utils/strings.rs b/src/utils/strings.rs new file mode 100644 index 0000000..a06c565 --- /dev/null +++ b/src/utils/strings.rs @@ -0,0 +1,42 @@ +// A Rust GitOps/symlinkfarm orchestrator inspired by GNU Stow. +// Copyright (C) 2023 Christina Sørensen +// +// 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. + +/// Contains the notice for interactive programs from the GPLv3's "How to Apply +/// These Terms to Your New Programs" +pub const INTERACTIVE_NOTICE: &str = "\ +gg Copyright (C) 2023 Christina Sørensen +This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. +This is free software, and you are welcome to redistribute it +under certain conditions; type `show c' for details. +"; + +/// Contains the license part of the long notice for interactive programs from +/// the GPLv3's "How to Apply These Terms to Your New Programs" +pub const INTERACTIVE_LICENSE: &str = "\ +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. +"; + +/// Contains the warranty part of the long notice for interactive programs from +/// the GPLv3's "How to Apply These Terms to Your New Programs" +pub const INTERACTIVE_WARRANTY: &str = "\ +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. +";