created Dockerfile, verbose fn, multiple configs option
This commit is contained in:
parent
cc9f36612d
commit
d8097ade47
5 changed files with 86 additions and 13 deletions
8
Dockerfile
Normal file
8
Dockerfile
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
FROM rust:latest
|
||||||
|
|
||||||
|
WORKDIR /usr/src/refractr
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN cargo install --path .
|
||||||
|
|
||||||
|
CMD ["refractr"]
|
11
src/common.rs
Normal file
11
src/common.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
pub fn verbose(level: u8, msg_lvl: u8, msg: String) {
|
||||||
|
if level < msg_lvl { return };
|
||||||
|
let mut prefix = String::new();
|
||||||
|
for i in 0..msg_lvl {
|
||||||
|
prefix += "=";
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix += "> ";
|
||||||
|
eprintln!("{}{}", prefix, msg);
|
||||||
|
}
|
|
@ -3,11 +3,10 @@ use std::path::PathBuf;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use toml;
|
use toml;
|
||||||
use serde_derive::Deserialize;
|
use serde_derive::Deserialize;
|
||||||
use std::process;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
from: Vec<String>,
|
from: String,
|
||||||
to: Vec<String>,
|
to: Vec<String>,
|
||||||
branches: Vec<String>,
|
branches: Vec<String>,
|
||||||
git: Git,
|
git: Git,
|
||||||
|
@ -25,17 +24,25 @@ struct Schedule {
|
||||||
duration: i32,
|
duration: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_config(path: PathBuf) -> Config {
|
pub fn read_config(paths: Vec<PathBuf>) -> Vec<Config> {
|
||||||
let mut data = String::new();
|
let mut configs: Vec<Config> = vec![];
|
||||||
let mut file = match File::open(path.as_path()) {
|
for path in paths {
|
||||||
Err(e) => panic!("unable to open {}: {}", path.as_path().display(), e),
|
let mut data = String::new();
|
||||||
Ok(file) => file
|
let mut file = match File::open(path.as_path()) {
|
||||||
};
|
Err(e) => panic!("unable to open {}: {}", path.as_path().display(), e),
|
||||||
|
Ok(file) => file
|
||||||
|
};
|
||||||
|
|
||||||
if let Err(e) = file.read_to_string(&mut data) {
|
if let Err(e) = file.read_to_string(&mut data) {
|
||||||
panic!("unable to read {}: {}", path.as_path().display(), e)
|
panic!("unable to read {}: {}", path.as_path().display(), e)
|
||||||
|
}
|
||||||
|
|
||||||
|
configs.push(verify_config(toml::from_str(&data).unwrap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let config: Config = toml::from_str(&data).unwrap();
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn verify_config(config: Config) -> Config {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
35
src/example/config.toml
Normal file
35
src/example/config.toml
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# ***********************************
|
||||||
|
# Example configuration for refractr
|
||||||
|
# ***********************************
|
||||||
|
|
||||||
|
[config]
|
||||||
|
# The "from" field is a string of the original/main repository you want to pull
|
||||||
|
# This field is REQUIRED
|
||||||
|
#from = "https://git.brysonsteck.xyz/brysonsteck/refractr"
|
||||||
|
|
||||||
|
# The "to" field is a list of strings of the repositories you want to push the repo
|
||||||
|
# from the "from" field to. These repositories must exist on the remote server
|
||||||
|
# It's recommended that you use SSH to avoid HTTPS authentication
|
||||||
|
# This field is REQUIRED
|
||||||
|
#to = ["git@codeberg.org:brysonsteck/refractr.git", "git@github.com:brysonsteck/refractr.git"]
|
||||||
|
|
||||||
|
# The "branches" field is a list of branches you want to mirror from the original
|
||||||
|
# repository.
|
||||||
|
# This field is OPTIONAL, will default to ["master"] if omitted
|
||||||
|
#branches = ["master"]
|
||||||
|
|
||||||
|
[git]
|
||||||
|
# The "ssh_identity_file" is your private SSH key that you will use to push updates
|
||||||
|
# from the original repository.
|
||||||
|
# This field is REQUIRED if you are using SSH to push, otherwise OPTIONAL
|
||||||
|
#ssh_identity_file = "/path/to/.ssh/id_rsa"
|
||||||
|
|
||||||
|
[schedule]
|
||||||
|
# The "enabled" field turns on the schedule feature of refractr.
|
||||||
|
# This field is REQUIRED.
|
||||||
|
#enabled = false
|
||||||
|
|
||||||
|
# The "duration" field is the amount of seconds refractor will wait before
|
||||||
|
# pulling updates from the original repository if the schedule feature is enabled.
|
||||||
|
# This field is REQUIRED if "enabled" is set to true, otherwise OPTIONAL
|
||||||
|
#duration = 300
|
16
src/main.rs
16
src/main.rs
|
@ -1,3 +1,4 @@
|
||||||
|
mod common;
|
||||||
mod config;
|
mod config;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
@ -10,7 +11,7 @@ use std::path::PathBuf;
|
||||||
#[command(long_about = None)]
|
#[command(long_about = None)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[arg(short, long, help = "Specify a config file", default_value = "/etc/refractr/config.toml")]
|
#[arg(short, long, help = "Specify a config file", default_value = "/etc/refractr/config.toml")]
|
||||||
config: PathBuf,
|
config: Vec<PathBuf>,
|
||||||
|
|
||||||
#[arg(short, long, help = "Specify the level of verbosity", action = clap::ArgAction::Count)]
|
#[arg(short, long, help = "Specify the level of verbosity", action = clap::ArgAction::Count)]
|
||||||
verbose: u8,
|
verbose: u8,
|
||||||
|
@ -21,5 +22,16 @@ struct Args {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let cfg = config::read_config(args.config);
|
if args.verbose >= 1 {
|
||||||
|
common::verbose(args.verbose, 1, format!("Level {} verbosity enabled", args.verbose.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
common::verbose(args.verbose, 2, format!("Checking for create flag"));
|
||||||
|
if args.create {
|
||||||
|
common::verbose(args.verbose, 2, format!("Printing sample config"));
|
||||||
|
let example = include_str!("example/config.toml");
|
||||||
|
println!("{}", example);
|
||||||
|
} else {
|
||||||
|
let cfg = config::read_config(args.config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue