License and license related flags #1
8 changed files with 158 additions and 27 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -190,7 +190,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gg"
|
name = "gg"
|
||||||
version = "0.0.1"
|
version = "0.0.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap_mangen",
|
"clap_mangen",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "gg"
|
name = "gg"
|
||||||
version = "0.0.1"
|
version = "0.0.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Christina Sørensen <christina@cafkafk.com>"]
|
authors = ["Christina Sørensen <christina@cafkafk.com>"]
|
||||||
repository = "https://github.com/cafkafk/gg"
|
repository = "https://github.com/cafkafk/gg"
|
||||||
|
|
47
src/cli.rs
47
src/cli.rs
|
@ -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::dir::home_dir;
|
||||||
|
use crate::utils::strings::INTERACTIVE_NOTICE;
|
||||||
|
|
||||||
use clap::{ArgAction, CommandFactory, Parser, Subcommand};
|
use clap::{ArgAction, CommandFactory, Parser, Subcommand};
|
||||||
|
|
||||||
const CONFIG_FILE: &str = "/.config/gg/config.yaml";
|
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)]
|
//#[clap(author, version, about, long_about = None)]
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[clap(
|
#[clap(
|
||||||
|
@ -13,16 +39,9 @@ const CONFIG_FILE: &str = "/.config/gg/config.yaml";
|
||||||
long_version=env!("CARGO_PKG_VERSION"),
|
long_version=env!("CARGO_PKG_VERSION"),
|
||||||
about="GitOps for the masses",
|
about="GitOps for the masses",
|
||||||
long_about="A Rust GitOps and linkfarm orchestrator inspired by GNU Stow",
|
long_about="A Rust GitOps and linkfarm orchestrator inspired by GNU Stow",
|
||||||
subcommand_required=true,
|
subcommand_required=false,
|
||||||
arg_required_else_help=true,
|
arg_required_else_help=true,
|
||||||
help_template="\
|
help_template=HELP_TEMPLATE.to_owned()+INTERACTIVE_NOTICE,
|
||||||
{before-help}{name} {version}
|
|
||||||
{author-with-newline}{about-with-newline}
|
|
||||||
{usage-heading} {usage}
|
|
||||||
|
|
||||||
{all-args}{after-help}
|
|
||||||
|
|
||||||
",
|
|
||||||
)]
|
)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
/// The config file to use
|
/// The config file to use
|
||||||
|
@ -30,16 +49,20 @@ pub struct Args {
|
||||||
#[arg(short, long, default_value_t = home_dir() + CONFIG_FILE)]
|
#[arg(short, long, default_value_t = home_dir() + CONFIG_FILE)]
|
||||||
pub config: String,
|
pub config: String,
|
||||||
|
|
||||||
/// Print full-text license information
|
/// Print license information
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub license: bool,
|
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)]
|
#[arg(long)]
|
||||||
pub code_of_conduct: bool,
|
pub code_of_conduct: bool,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Commands,
|
pub command: Option<Commands>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
|
|
24
src/git.rs
24
src/git.rs
|
@ -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 log::{debug, error, info, trace, warn};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::os::unix::fs::symlink;
|
use std::os::unix::fs::symlink;
|
||||||
|
@ -98,7 +114,7 @@ impl GitRepo {
|
||||||
/// Pulls the repository if able.
|
/// Pulls the repository if able.
|
||||||
fn pull(&self) {
|
fn pull(&self) {
|
||||||
let out = Command::new("git")
|
let out = Command::new("git")
|
||||||
.current_dir(&(self.path.to_owned() + &self.name))
|
.current_dir(format!("{}{}", &self.path, &self.name))
|
||||||
.arg("pull")
|
.arg("pull")
|
||||||
.status()
|
.status()
|
||||||
.expect("failed to pull");
|
.expect("failed to pull");
|
||||||
|
@ -118,7 +134,7 @@ impl GitRepo {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn commit(&self) {
|
fn commit(&self) {
|
||||||
let out = Command::new("git")
|
let out = Command::new("git")
|
||||||
.current_dir(&(self.path.to_owned() + &self.name))
|
.current_dir(format!("{}{}", &self.path, &self.name))
|
||||||
.arg("commit")
|
.arg("commit")
|
||||||
.status()
|
.status()
|
||||||
.expect("failed to commit");
|
.expect("failed to commit");
|
||||||
|
@ -127,7 +143,7 @@ impl GitRepo {
|
||||||
/// Tries to commit changes with a message argument.
|
/// Tries to commit changes with a message argument.
|
||||||
fn commit_with_msg(&self, msg: &String) {
|
fn commit_with_msg(&self, msg: &String) {
|
||||||
let out = Command::new("git")
|
let out = Command::new("git")
|
||||||
.current_dir(&(self.path.to_owned() + &self.name))
|
.current_dir(format!("{}{}", &self.path, &self.name))
|
||||||
.arg("commit")
|
.arg("commit")
|
||||||
.arg("-m")
|
.arg("-m")
|
||||||
.arg(msg)
|
.arg(msg)
|
||||||
|
@ -138,7 +154,7 @@ impl GitRepo {
|
||||||
/// Attempts to push the repository.
|
/// Attempts to push the repository.
|
||||||
fn push(&self) {
|
fn push(&self) {
|
||||||
let out = Command::new("git")
|
let out = Command::new("git")
|
||||||
.current_dir(&(self.path.to_owned() + &self.name))
|
.current_dir(format!("{}{}", &self.path, &self.name))
|
||||||
.arg("push")
|
.arg("push")
|
||||||
.status()
|
.status()
|
||||||
.expect("failed to push");
|
.expect("failed to push");
|
||||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -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 log;
|
||||||
extern crate pretty_env_logger;
|
extern crate pretty_env_logger;
|
||||||
|
|
||||||
|
@ -20,33 +36,34 @@ fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let config = Config::new(&args.config);
|
let config = Config::new(&args.config);
|
||||||
match &args {
|
match &args {
|
||||||
//args if args.quick == true => config.quick(&args.quick),
|
args if args.license == true => println!("{}", utils::strings::INTERACTIVE_LICENSE),
|
||||||
args if args.license == true => unimplemented!(),
|
args if args.warranty == true => println!("{}", utils::strings::INTERACTIVE_WARRANTY),
|
||||||
args if args.code_of_conduct == true => unimplemented!(),
|
args if args.code_of_conduct == true => unimplemented!(),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
match &args.command {
|
match &args.command {
|
||||||
Commands::Link { msg: _ } => {
|
Some(Commands::Link { msg: _ }) => {
|
||||||
config.link_all();
|
config.link_all();
|
||||||
}
|
}
|
||||||
Commands::Quick { msg } => {
|
Some(Commands::Quick { msg }) => {
|
||||||
config.quick(&msg.as_ref().unwrap());
|
config.quick(&msg.as_ref().unwrap());
|
||||||
}
|
}
|
||||||
Commands::Clone { msg: _ } => {
|
Some(Commands::Clone { msg: _ }) => {
|
||||||
config.clone_all();
|
config.clone_all();
|
||||||
}
|
}
|
||||||
Commands::Pull { msg: _ } => {
|
Some(Commands::Pull { msg: _ }) => {
|
||||||
config.pull_all();
|
config.pull_all();
|
||||||
}
|
}
|
||||||
Commands::Add { msg: _ } => {
|
Some(Commands::Add { msg: _ }) => {
|
||||||
config.add_all();
|
config.add_all();
|
||||||
}
|
}
|
||||||
Commands::Commit { msg: _ } => {
|
Some(Commands::Commit { msg: _ }) => {
|
||||||
config.commit_all();
|
config.commit_all();
|
||||||
}
|
}
|
||||||
Commands::CommitMsg { msg } => {
|
Some(Commands::CommitMsg { msg }) => {
|
||||||
config.commit_all_msg(&msg.as_ref().unwrap());
|
config.commit_all_msg(&msg.as_ref().unwrap());
|
||||||
}
|
}
|
||||||
|
None => (),
|
||||||
}
|
}
|
||||||
trace!("{:?}", config);
|
trace!("{:?}", config);
|
||||||
}
|
}
|
||||||
|
|
17
src/utils.rs
17
src/utils.rs
|
@ -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 dir;
|
||||||
|
pub mod strings;
|
||||||
|
|
|
@ -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)]
|
#![feature(stmt_expr_attributes)]
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
|
|
||||||
|
|
42
src/utils/strings.rs
Normal file
42
src/utils/strings.rs
Normal 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.
|
||||||
|
";
|
Loading…
Reference in a new issue