mirror of
https://github.com/philmmanjaro/alma.git
synced 2025-07-26 23:19:29 +02:00
Move the command line arguments to a module
This commit is contained in:
parent
ec1f74b05d
commit
10faad551b
56
src/args.rs
Normal file
56
src/args.rs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
use std::path::PathBuf;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
|
#[derive(StructOpt)]
|
||||||
|
#[structopt(name = "alma", about = "Arch Linux Mobile Appliance")]
|
||||||
|
pub struct App {
|
||||||
|
/// Verbose output
|
||||||
|
#[structopt(short = "v", long = "verbose")]
|
||||||
|
pub verbose: bool,
|
||||||
|
|
||||||
|
#[structopt(subcommand)]
|
||||||
|
pub cmd: Command,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt)]
|
||||||
|
pub enum Command {
|
||||||
|
#[structopt(name = "create", about = "Create a new Arch Linux USB")]
|
||||||
|
Create(CreateCommand),
|
||||||
|
|
||||||
|
#[structopt(name = "chroot", about = "Chroot into exiting Live USB")]
|
||||||
|
Chroot(ChrootCommand),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt)]
|
||||||
|
pub struct CreateCommand {
|
||||||
|
/// Path starting with /dev/disk/by-id for the USB drive
|
||||||
|
#[structopt(parse(from_os_str))]
|
||||||
|
pub block_device: PathBuf,
|
||||||
|
|
||||||
|
/// Additional pacakges to install
|
||||||
|
#[structopt(short = "p", long = "extra-packages", value_name = "package")]
|
||||||
|
pub extra_packages: Vec<String>,
|
||||||
|
|
||||||
|
/// Enter interactive chroot before unmounting the drive
|
||||||
|
#[structopt(short = "i", long = "interactive")]
|
||||||
|
pub interactive: bool,
|
||||||
|
|
||||||
|
/// Encrypt the root partition
|
||||||
|
#[structopt(short = "e", long = "encrypted-root")]
|
||||||
|
pub encrypted_root: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(StructOpt)]
|
||||||
|
pub struct ChrootCommand {
|
||||||
|
/// Path starting with /dev/disk/by-id for the USB drive
|
||||||
|
#[structopt(parse(from_os_str))]
|
||||||
|
pub block_device: PathBuf,
|
||||||
|
|
||||||
|
/// Open an encrypted root partition
|
||||||
|
#[structopt(short = "e", long = "encrypted-root")]
|
||||||
|
pub encrypted_root: bool,
|
||||||
|
|
||||||
|
/// Optional command to run
|
||||||
|
#[structopt()]
|
||||||
|
pub command: Vec<String>,
|
||||||
|
}
|
58
src/main.rs
58
src/main.rs
@ -1,8 +1,10 @@
|
|||||||
|
mod args;
|
||||||
mod error;
|
mod error;
|
||||||
mod process;
|
mod process;
|
||||||
mod storage;
|
mod storage;
|
||||||
mod tool;
|
mod tool;
|
||||||
|
|
||||||
|
use crate::args::*;
|
||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
use crate::process::CommandExt;
|
use crate::process::CommandExt;
|
||||||
use crate::storage::*;
|
use crate::storage::*;
|
||||||
@ -13,7 +15,7 @@ use nix::sys::signal;
|
|||||||
use simplelog::*;
|
use simplelog::*;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
@ -34,60 +36,6 @@ Storage=volatile
|
|||||||
SystemMaxUse=16M
|
SystemMaxUse=16M
|
||||||
";
|
";
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
|
||||||
#[structopt(name = "alma", about = "Arch Linux Mobile Appliance")]
|
|
||||||
struct App {
|
|
||||||
/// Verbose output
|
|
||||||
#[structopt(short = "v", long = "verbose")]
|
|
||||||
verbose: bool,
|
|
||||||
|
|
||||||
#[structopt(subcommand)]
|
|
||||||
cmd: Command,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
|
||||||
enum Command {
|
|
||||||
#[structopt(name = "create", about = "Create a new Arch Linux USB")]
|
|
||||||
Create(CreateCommand),
|
|
||||||
|
|
||||||
#[structopt(name = "chroot", about = "Chroot into exiting Live USB")]
|
|
||||||
Chroot(ChrootCommand),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
|
||||||
struct CreateCommand {
|
|
||||||
/// Path starting with /dev/disk/by-id for the USB drive
|
|
||||||
#[structopt(parse(from_os_str))]
|
|
||||||
block_device: PathBuf,
|
|
||||||
|
|
||||||
/// Additional pacakges to install
|
|
||||||
#[structopt(short = "p", long = "extra-packages", value_name = "package")]
|
|
||||||
extra_packages: Vec<String>,
|
|
||||||
|
|
||||||
/// Enter interactive chroot before unmounting the drive
|
|
||||||
#[structopt(short = "i", long = "interactive")]
|
|
||||||
interactive: bool,
|
|
||||||
|
|
||||||
/// Encrypt the root partition
|
|
||||||
#[structopt(short = "e", long = "encrypted-root")]
|
|
||||||
encrypted_root: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
|
||||||
struct ChrootCommand {
|
|
||||||
/// Path starting with /dev/disk/by-id for the USB drive
|
|
||||||
#[structopt(parse(from_os_str))]
|
|
||||||
block_device: PathBuf,
|
|
||||||
|
|
||||||
/// Open an encrypted root partition
|
|
||||||
#[structopt(short = "e", long = "encrypted-root")]
|
|
||||||
encrypted_root: bool,
|
|
||||||
|
|
||||||
/// Optional command to run
|
|
||||||
#[structopt()]
|
|
||||||
command: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn mount<'a>(
|
fn mount<'a>(
|
||||||
mount_path: &Path,
|
mount_path: &Path,
|
||||||
boot_filesystem: &'a Filesystem,
|
boot_filesystem: &'a Filesystem,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user