Removed configure subcommand for now; Added setup subcommand to initialize the video repository
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2022-10-21 19:37:45 -04:00
parent 0b327f304e
commit 004c057a2c
3 changed files with 23 additions and 30 deletions

View File

@ -1,24 +1,14 @@
use std::io;
use std::io::Write;
use config::Config;
use crate::settings;
use crate::transcoder::repository::Repository;
pub fn configure_command(config_path: &str) {
let repository_dir = get_user_input("Enter your desired video repository directory path: ");
let interval = get_user_input("Enter how long Zealot should wait in between runs (in minutes): ");
pub fn setup_command(repository_dir: &str) {
println!("Initializing video repository at {}...", repository_dir);
println!("Updating config file {} with repository path {} and interval {}.", config_path, repository_dir, interval);
}
fn get_user_input(message: &str) -> String {
// print our message to the user, then flush STDIN so the message is sent
print!("{}", message);
io::stdout().flush().unwrap();
// now create our string object and read the input
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to get user input");
// obviously, return the trimmed result as a String object
return input.trim().to_string();
// create and initialize our config and repository objects
let c: Config = settings::load_config();
let r: Repository = Repository::new(&shellexpand::tilde(&c.get_string("transcoder.repository").unwrap()));
// initialize the video repository
r.initialize();
}

View File

@ -19,7 +19,7 @@ struct Cli {
#[derive(Subcommand)]
enum Commands {
/// displays version info about this program
Configure {},
Setup {},
}
fn main() {
@ -37,7 +37,7 @@ fn main() {
match &cli.command {
// sub-commands will be handled here
Some(Commands::Configure {}) => cmd::core::configure_command(config_path),
Some(Commands::Setup {}) => cmd::core::setup_command(config_path),
// run the main program without any commands
None => {

View File

@ -11,16 +11,9 @@ pub struct Repository {
impl Repository {
pub fn new(base_path: &str) -> Repository {
// create the base directory path
create_directory(base_path);
// create the needed sub-directories
let ingest_path = Path::new(base_path).join("ingest");
create_directory(ingest_path.to_str().unwrap());
let archive_path = Path::new(base_path).join("archive");
create_directory(archive_path.to_str().unwrap());
let output_path = Path::new(base_path).join("output");
create_directory(output_path.to_str().unwrap());
return Repository {
base_dir: String::from(base_path),
@ -30,6 +23,16 @@ impl Repository {
};
}
pub fn initialize(&self) {
// create the base directory path
create_directory(&self.base_dir);
// create the needed sub-directories
create_directory(&self.ingest_dir.as_str());
create_directory(&self.archive_dir.as_str());
create_directory(&self.output_dir.as_str());
}
pub fn search_ingest(&self) -> Vec<String> {
// read file entries from ingest
let files = fs::read_dir(&self.ingest_dir).unwrap();