Commit 862ed8c1 authored by Wren Turkal's avatar Wren Turkal

Add more structure cli to pcid.

This change adds a subcommand `daemonize` that does what pcid
previously did by defualt. This for +1/-1 compat so that the
existing config in the redox repo doesn't break with this change.
This backward compatibility will be removed after that repo gets
the updated config.
Signed-off-by: Wren Turkal's avatarWren Turkal <wt@penguintechs.org>
parent a16604fc
This diff is collapsed.
......@@ -17,11 +17,13 @@ bitflags = "1"
byteorder = "1.2"
libc = "0.2"
log = "0.4"
paw = "1.0"
plain = "0.2"
redox-log = { git = "https://gitlab.redox-os.org/redox-os/redox-log.git", tag = "v0.1.0" }
redox_syscall = { git = "https://gitlab.redox-os.org/redox-os/syscall.git" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
smallvec = "1"
structopt = { version = "0.3", features = [ "paw" ] }
thiserror = "1"
toml = "0.5"
......@@ -9,6 +9,7 @@ use std::{env, io, i64, thread};
use syscall::iopl;
use structopt::StructOpt;
use log::{error, info, warn, trace};
use redox_log::{OutputBuilder, RedoxLogger};
......@@ -22,6 +23,29 @@ mod driver_interface;
mod pci;
mod pcie;
#[derive(StructOpt)]
#[structopt(about)]
struct Args {
#[structopt(subcommand)]
subcommand: Option<Subcommand>,
// Backware compatibility to be removed after start scripts use
// deamonize subcommand.
#[structopt()]
config_path: Option<String>,
}
#[derive(StructOpt)]
enum Subcommand {
Daemonize(DaemonizeArgs),
}
#[derive(StructOpt)]
struct DaemonizeArgs {
#[structopt()]
config_path: String,
}
pub struct DriverHandler {
config: config::DriverConfig,
bus_num: u8,
......@@ -513,34 +537,50 @@ fn setup_logging() -> Option<&'static RedoxLogger> {
}
}
fn main() {
let mut config = Config::default();
let mut args = env::args().skip(1);
if let Some(config_path) = args.next() {
if metadata(&config_path).unwrap().is_file() {
if let Ok(mut config_file) = File::open(&config_path) {
let mut config_data = String::new();
if let Ok(_) = config_file.read_to_string(&mut config_data) {
config = toml::from_str(&config_data).unwrap_or(Config::default());
}
#[paw::main]
fn main(args: Args) {
match args.subcommand {
Some(command) => match command {
Subcommand::Daemonize(daemonize_args) => daemonize_main(&daemonize_args),
},
None => {
// Backware compatibility to be removed after start scripts use
// deamonize subcommand.
if let Some(config_path) = args.config_path {
let daemonize_args = DaemonizeArgs {
config_path: config_path.clone(),
};
daemonize_main(&daemonize_args)
}
} else {
let paths = read_dir(&config_path).unwrap();
}
}
}
fn daemonize_main(args: &DaemonizeArgs) {
let mut config = Config::default();
let config_path = &args.config_path;
if metadata(&config_path).unwrap().is_file() {
if let Ok(mut config_file) = File::open(&config_path) {
let mut config_data = String::new();
if let Ok(_) = config_file.read_to_string(&mut config_data) {
config = toml::from_str(&config_data).unwrap_or(Config::default());
}
}
} else {
let paths = read_dir(&config_path).unwrap();
for path in paths {
if let Ok(mut config_file) = File::open(&path.unwrap().path()) {
let mut tmp = String::new();
if let Ok(_) = config_file.read_to_string(&mut tmp) {
config_data.push_str(&tmp);
}
let mut config_data = String::new();
for path in paths {
if let Ok(mut config_file) = File::open(&path.unwrap().path()) {
let mut tmp = String::new();
if let Ok(_) = config_file.read_to_string(&mut tmp) {
config_data.push_str(&tmp);
}
}
config = toml::from_str(&config_data).unwrap_or(Config::default());
}
config = toml::from_str(&config_data).unwrap_or(Config::default());
}
let _logger_ref = setup_logging();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment