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 toml;
|
||||
use serde_derive::Deserialize;
|
||||
use std::process;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Config {
|
||||
from: Vec<String>,
|
||||
from: String,
|
||||
to: Vec<String>,
|
||||
branches: Vec<String>,
|
||||
git: Git,
|
||||
|
@ -25,17 +24,25 @@ struct Schedule {
|
|||
duration: i32,
|
||||
}
|
||||
|
||||
pub fn read_config(path: PathBuf) -> Config {
|
||||
let mut data = String::new();
|
||||
let mut file = match File::open(path.as_path()) {
|
||||
Err(e) => panic!("unable to open {}: {}", path.as_path().display(), e),
|
||||
Ok(file) => file
|
||||
};
|
||||
pub fn read_config(paths: Vec<PathBuf>) -> Vec<Config> {
|
||||
let mut configs: Vec<Config> = vec![];
|
||||
for path in paths {
|
||||
let mut data = String::new();
|
||||
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) {
|
||||
panic!("unable to read {}: {}", path.as_path().display(), e)
|
||||
if let Err(e) = file.read_to_string(&mut data) {
|
||||
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;
|
||||
}
|
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;
|
||||
|
||||
use clap::Parser;
|
||||
|
@ -10,7 +11,7 @@ use std::path::PathBuf;
|
|||
#[command(long_about = None)]
|
||||
struct Args {
|
||||
#[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)]
|
||||
verbose: u8,
|
||||
|
@ -21,5 +22,16 @@ struct Args {
|
|||
|
||||
fn main() {
|
||||
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