From 43e522e563309cc52fc3080a227c93d73475a008 Mon Sep 17 00:00:00 2001 From: Kreyren Date: Sun, 19 Jan 2020 14:17:39 +0000 Subject: [PATCH] stub --- src/bin/main-experiment.rs | 17 ++++++ src/bin/main.rs | 110 +++++++++++++++++++++++++++++++++++-- src/lib.rs | 4 -- 3 files changed, 121 insertions(+), 10 deletions(-) delete mode 100644 src/lib.rs diff --git a/src/bin/main-experiment.rs b/src/bin/main-experiment.rs index e69de29..631ef83 100644 --- a/src/bin/main-experiment.rs +++ b/src/bin/main-experiment.rs @@ -0,0 +1,17 @@ +// will accept any object that implements AsRef +fn print>(test: S) { + // call as_ref() to get a &str + let str_ref = test.as_ref(); + + println!("got: {:?}", str_ref) +} + +fn main() { + let a: &str = "str"; + let b: String = String::from("String"); + let c: &String = &b; + + print(a); + print(c); + print(b); +} \ No newline at end of file diff --git a/src/bin/main.rs b/src/bin/main.rs index 32593a3..be4757a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -4,18 +4,58 @@ extern crate clap; use clap::{Arg, App, SubCommand}; +// Export for metadata? +/// FIXME: Verify unused +use std::fs; + + +// Export of standard library to make a new directory (works cross-platform) +/// FIXME: Make create_dir to output TRACE message of level 2 +/// FIXME: Output helpful error in CLI and logs +use std::fs::create_dir; + // Get die macro /// FIXME: Contribute in die crate to allow customization of messages by the end-user use die::die; +// Required for create_dir +use std::fs::metadata; + +// Required for emkdir +use std::io; + // Macro to handle fixme messages +// FIXME: Implement export in log directory based on system used +// FIXME: Allow end-user to customize the message +// FIXME: Allow end-user to mute the messages through configuration +// FIXME: Contribute in log to outsource maintainance on them +macro_rules! fixme { + ($msg:expr) => ( println!("FIXME: {}", $msg);) +} + +// Macro to inform the end-user about non-fatal error +// FIXME: Implement export in log directory based on system used +// FIXME: Allow end-user to customize the message +// FIXME: Contribute in log to outsource maintainance on them +macro_rules! error { + ($msg:expr) => ( println!("ERROR: {}", $msg);) +} + +// Macro to perform tracing +// FIXME: Implement export in log directory based on system used and debug level +// FIXME: Allow end-user to customize the message +// FIXME: Contribute in log to outsource maintainance on them +// FIXME: Output only if debug level 2 and higger is used +macro_rules! trace { + ($msg:expr) => ( println!("TRACE: {}", $msg);) +} + +// Macro to handle info messages /// FIXME: Implement export in log directory based on system used /// FIXME: Outsource parts of the code in log crate? /// FIXME: Allow end-user to customize the message -/// FIXME: Allow end-user to mute the messages through configuration -/// FIXME: Contribute in log to outsource maintainance on them -macro_rules! fixme { - ($msg:expr) => ( println!("FIXME: {}", $msg);) +macro_rules! info { + ($msg:expr) => ( println!("INFO: {}", $msg);) } // Macro to overwrite default `unimplemented!();` to be more user-friendly @@ -26,10 +66,41 @@ macro_rules! unimplemented { ) } +// Sanitized method to make a new directory +fn emkdir>(pathname: PATH) { + unimplemented!("Mkdir needs implementation"); + // FIXME: Verify that parsed argument is valid + // FIXME-TEST: Make sure that this works on Linux + // FIXME-TEST: Make sure that this works on Windows + // FIXME-TEST: Make sure that this works on Redox + // FIXME-TEST: Make sure that this works on MacOS + // FIXME-TEST: Make sure that this works on FreeBSD + fixme!("Die() doesn't accept pathname println!();-way, using some/path as stub"); + if metadata(pathname).unwrap().is_dir() { + match fs::create_dir(pathname) { // FIXME: This fails + Ok(..) => { info!("Created a new directory in some/path"); }, + Err(ref e) if e.kind() == io::ErrorKind::AlreadyExists => { + unimplemented!("Unexpected happend while creating new directory in some/path checking for already existing"); + // FIXME: Check if file or a directory + }, + Err(e) => { die!(256; "Unexpected happend while creating a directory some/path"); } + } + } else if metadata(pathname).unwrap().is_dir() { + info!("Directory {} already exists"); + } else if metadata(pathname).unwrap().is_file() { + // FIXMEL die!(1; "Path {} is already a file which is unexpected", pathname); + die!(1; "Path some/path is already a file which is unexpected"); + } else if false { // FIXME: Implement checking for symlink + die!(1; "Path some/path is a symlink which is unexpected for creating a directory"); + } else { + die!(256; "Unexpected happend while creating a new directory in some/path"); + } +} + fn main() { fixme!("Add method to handle translations"); - fixme!("Returns 0 even when no argument was parsed -> Expecting Exit 2 with help message"); fixme!("Allow changing name based on config file"); + fixme!("Verify that this works on POSIX"); // Capture arguments (https://docs.rs/clap/2.33.0/clap/) // FIXME: Check if structOpt (https://docs.rs/structopt/0.3.7/structopt/#subcommands) is not better for our usecase @@ -43,6 +114,11 @@ fn main() { .long("gui") .multiple(true) .help("Opens up a Graphical User Interface frontend")) + .arg(Arg::with_name("dev") + .short("D") + .long("development") + .multiple(true) + .help("Perform all following actions in a temporary sandboxed directory used for development")) // FIXME-QA: Sort subcommands alphabetically .subcommand(SubCommand::with_name("resolve") .about("Resolved package to be imported in the system") @@ -67,13 +143,20 @@ fn main() { // NOTICE: Do not add else statement to catch unexpecteds since this is handled by clap if matches.is_present("gui") { unimplemented!("GUI method is not yet implemented"); + } else if matches.is_present("dev") { + // WARNING: Has to be implemented prior to implementing other features + // FIXME-TEST: Make a test to ensure that features are not escaping sandbox + // FIXME: Translate in rustlang from english + fixme!("Create a new directory in tmpdir/name-of-project"); + fixme!("Create sandboxed environment for testing of features"); + unimplemented!("Development method is not yet supported"); } // Manage subcommands // NOTICE: Do not add else statement to catch unexpecteds since this is handled by clap // FIXME: Convert this statement in case which would seem like better implementation if let Some(_matches) = matches.subcommand_matches("resolve") { - // Current approach: Download source to + // Current approach: Download source to ... ? fixme!("Check if expected file hierarchy is present, if not prompt for init subcommand"); fixme!("Initiate sandbox"); fixme!("Allow multiple methods of sandboxing"); @@ -100,8 +183,23 @@ fn main() { fixme!("Expected feature: Kreyrock"); fixme!("Expected feature: winehq for unix"); unimplemented!("Listing is not yet implemented"); + } else if let Some(_matches) = matches.subcommand_matches("deploy") { + fixme!("Perform sanity-checks for hijacking"); + fixme!("Hijack apt"); + fixme!("Hijack pacman"); + fixme!("Hijack portage"); + fixme!("Hijack dnf"); + fixme!("Hijack zypper"); + fixme!("Hijack freebsd pckm"); + fixme!("Hijack MacOS"); + fixme!("Hijack Windows?"); + fixme!("Die if untested system is parsed"); + fixme!("Die if used on invalid directory (suggest deploy instead?)"); + unimplemented!("Hijacking is not yet supported"); } else if let Some(_matches) = matches.subcommand_matches("remove") { fixme!("Remove package from specified root"); unimplemented!("Removal of packages from specified root is not yet supported"); } + + fixme!("Returns 0 even when no argument was parsed -> Expecting Exit 2 with help message"); } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 726301e..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -// Library used for cli argument management -use clap::{Arg, App, SubCommand}; - -use log::{info, trace, warn}; \ No newline at end of file