0.2.18 - allow use as a library

parent a6548498
......@@ -823,7 +823,7 @@ dependencies = [
[[package]]
name = "redoxer"
version = "0.2.17"
version = "0.2.18"
dependencies = [
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-mounts 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package]
name = "redoxer"
version = "0.2.17"
version = "0.2.18"
description = "Method for quickly running programs inside of Redox from a KVM capable OS."
license = "MIT"
authors = ["Jeremy Soller <jackpot51@gmail.com>"]
......
......@@ -3,7 +3,7 @@ use std::ffi::OsString;
use crate::{status_error, toolchain, TARGET};
fn inner() -> io::Result<()> {
fn inner<I: Iterator<Item=String>>(mut args: I) -> io::Result<()> {
let toolchain_dir = toolchain()?;
// PATH must be set first so cargo is sourced from the toolchain path
......@@ -24,7 +24,6 @@ fn inner() -> io::Result<()> {
toolchain_dir.join(TARGET).join("lib").display()
);
let mut args = env::args();
let command = args.next().unwrap();
let subcommand = args.next().unwrap();
......@@ -64,8 +63,8 @@ fn inner() -> io::Result<()> {
Ok(())
}
pub fn main() {
match inner() {
pub fn main(args: &[String]) {
match inner(args.iter().cloned()) {
Ok(()) => {
process::exit(0);
},
......
......@@ -34,10 +34,10 @@ pub fn command<S: AsRef<ffi::OsStr>>(program: S) -> io::Result<process::Command>
Ok(command)
}
fn inner() -> io::Result<()> {
fn inner<I: Iterator<Item=String>>(args: I) -> io::Result<()> {
let mut program_opt = None;
let mut arguments = Vec::new();
for arg in env::args().skip(2) {
for arg in args.skip(2) {
if program_opt.is_none() {
program_opt = Some(arg);
} else {
......@@ -55,8 +55,8 @@ fn inner() -> io::Result<()> {
Ok(())
}
pub fn main() {
match inner() {
pub fn main(args: &[String]) {
match inner(args.iter().cloned()) {
Ok(()) => {
process::exit(0);
},
......
use redoxfs::{archive_at, BLOCK_SIZE, DiskSparse, FileSystem};
use std::{env, fs, io};
use std::{fs, io};
use std::io::{Seek, Write};
use std::path::{Path, PathBuf};
use std::process::{self, Command};
......@@ -355,7 +355,7 @@ fn usage() {
process::exit(1);
}
pub fn main() {
pub fn main(args: &[String]) {
// Matching flags
let mut matching = true;
// Folder to copy
......@@ -365,7 +365,7 @@ pub fn main() {
// Arguments to pass to command
let mut arguments = Vec::new();
let mut args = env::args().skip(2);
let mut args = args.iter().cloned().skip(2);
while let Some(arg) = args.next() {
match arg.as_str() {
"-f" | "--folder" if matching => match args.next() {
......
use std::{io, path, process};
pub (crate) use self::toolchain::toolchain;
mod cargo;
mod env;
mod exec;
mod redoxfs;
mod toolchain;
static TARGET: &'static str = "x86_64-unknown-redox";
//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
fn installed(program: &str) -> io::Result<bool> {
process::Command::new("which")
.arg(program)
.stdout(process::Stdio::null())
.status()
.map(|x| x.success())
}
fn redoxer_dir() -> path::PathBuf {
dirs::home_dir().unwrap_or(path::PathBuf::from("."))
.join(".redoxer")
}
//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
fn running(program: &str) -> io::Result<bool> {
process::Command::new("pgrep")
.arg(program)
.stdout(process::Stdio::null())
.status()
.map(|x| x.success())
}
fn status_error(status: process::ExitStatus) -> io::Result<()> {
if status.success() {
Ok(())
} else {
Err(io::Error::new(
io::ErrorKind::Other,
format!("{}", status)
))
}
}
fn syscall_error(err: syscall::Error) -> io::Error {
io::Error::from_raw_os_error(err.errno)
}
fn usage() {
eprintln!("redoxer bench - cargo bench with Redox target in Redox VM");
eprintln!("redoxer build - cargo build with Redox target");
eprintln!("redoxer check - cargo check with Redox target");
eprintln!("redoxer doc - cargo doc with Redox target");
eprintln!("redoxer env - execute a command in cross-compilation environment");
eprintln!("redoxer exec - execute a command in Redox VM");
eprintln!("redoxer install - cargo install with Redox target");
eprintln!("redoxer run - cargo run with Redox target in Redox VM");
eprintln!("redoxer rustc - cargo rustc with Redox target");
eprintln!("redoxer test - cargo test with Redox target in Redox VM");
eprintln!("redoxer toolchain - install toolchain");
process::exit(1);
}
pub fn main(args: &[String]) {
match args.get(1) {
Some(arg) => match arg.as_str() {
"bench" |
"build" |
"check" |
"doc" |
"install" |
"run" |
"rustc" |
"test" => cargo::main(args),
"env" => env::main(args),
"exec" => exec::main(args),
"toolchain" => toolchain::main(args),
_ => usage(),
},
None => usage(),
}
}
use std::{env::args, io, path, process};
pub (crate) use self::toolchain::toolchain;
mod cargo;
mod env;
mod exec;
mod redoxfs;
mod toolchain;
static TARGET: &'static str = "x86_64-unknown-redox";
//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
fn installed(program: &str) -> io::Result<bool> {
process::Command::new("which")
.arg(program)
.stdout(process::Stdio::null())
.status()
.map(|x| x.success())
}
fn redoxer_dir() -> path::PathBuf {
dirs::home_dir().unwrap_or(path::PathBuf::from("."))
.join(".redoxer")
}
//TODO: Confirm capabilities on other OSes
#[cfg(target_os = "linux")]
fn running(program: &str) -> io::Result<bool> {
process::Command::new("pgrep")
.arg(program)
.stdout(process::Stdio::null())
.status()
.map(|x| x.success())
}
fn status_error(status: process::ExitStatus) -> io::Result<()> {
if status.success() {
Ok(())
} else {
Err(io::Error::new(
io::ErrorKind::Other,
format!("{}", status)
))
}
}
fn syscall_error(err: syscall::Error) -> io::Error {
io::Error::from_raw_os_error(err.errno)
}
fn usage() {
eprintln!("redoxer bench - cargo bench with Redox target in Redox VM");
eprintln!("redoxer build - cargo build with Redox target");
eprintln!("redoxer check - cargo check with Redox target");
eprintln!("redoxer doc - cargo doc with Redox target");
eprintln!("redoxer env - execute a command in cross-compilation environment");
eprintln!("redoxer exec - execute a command in Redox VM");
eprintln!("redoxer install - cargo install with Redox target");
eprintln!("redoxer run - cargo run with Redox target in Redox VM");
eprintln!("redoxer rustc - cargo rustc with Redox target");
eprintln!("redoxer test - cargo test with Redox target in Redox VM");
eprintln!("redoxer toolchain - install toolchain");
process::exit(1);
}
use std::env;
fn main() {
match args().nth(1) {
Some(arg) => match arg.as_str() {
"bench" |
"build" |
"check" |
"doc" |
"install" |
"run" |
"rustc" |
"test" => cargo::main(),
"env" => env::main(),
"exec" => exec::main(),
"toolchain" => toolchain::main(),
_ => usage(),
},
None => usage(),
}
let args: Vec<String> = env::args().collect();
redoxer::main(&args);
}
......@@ -78,7 +78,7 @@ pub fn toolchain() -> io::Result<PathBuf> {
Ok(toolchain_dir)
}
pub fn main() {
pub fn main(_args: &[String]) {
match toolchain() {
Ok(_) => {
process::exit(0);
......
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