License and license related flags #1

Merged
cafkafk merged 13 commits from dev into main 2023-06-09 18:36:30 +02:00
8 changed files with 158 additions and 27 deletions

2
Cargo.lock generated
View file

@ -190,7 +190,7 @@ dependencies = [
[[package]]
name = "gg"
version = "0.0.1"
version = "0.0.2"
dependencies = [
"clap",
"clap_mangen",

View file

@ -1,6 +1,6 @@
[package]
name = "gg"
version = "0.0.1"
version = "0.0.2"
edition = "2021"
authors = ["Christina Sørensen <christina@cafkafk.com>"]
repository = "https://github.com/cafkafk/gg"

View file

@ -1,9 +1,35 @@
// 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.
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<Commands>,
}
#[derive(Subcommand, Debug)]

View file

@ -1,3 +1,19 @@
// 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.
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");

View file

@ -1,3 +1,19 @@
// 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.
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);
}

View file

@ -1 +1,18 @@
// 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.
pub mod dir;
pub mod strings;

View file

@ -1,3 +1,19 @@
// 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.
#![feature(stmt_expr_attributes)]
use log::{debug, error, info, trace, warn};

42
src/utils/strings.rs Normal file
View file

@ -0,0 +1,42 @@
// 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.
/// 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 <christina@cafkafk.com>
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.
";