rusty-axml 0.2.1

A parser for Android AXML files
Documentation
//! Command line args
//!
//! This is only used in the binary crate.

use std::path::PathBuf;
use clap::Parser;

/// Accepted file types
#[derive(Debug, PartialEq)]
pub enum ArgType {
    Apk,
    Axml,
    Arsc
}

/// Basic CLI for the binary
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
    /// Path to the file to parse. The file can be either an APK, an Android
    /// binary-XML file, or a resource.arsc file.
    #[clap(flatten)]
    pub target: Target,

    /// Path to the output file to write the decoded content
    #[arg(short, long)]
    pub output: Option<PathBuf>,
}

/// Argument group to represent any file that can be parsed by AXMLParser
#[derive(Debug, clap::Args)]
#[group(required = true, multiple = false)]
pub struct Target {
   /// Path to an APK
   #[arg(short, long)]
   apk: Option<PathBuf>,

   /// Path to an Android binary XML file
   #[arg(short, long)]
   xml: Option<PathBuf>,

   // /// Path to resources.arsc file
   // #[arg(short, long)]
   // res: Option<String>,
}

pub fn parse_args() -> Args {
    Args::parse()
}

impl Args {
    pub fn get_arg_type(&self) -> ArgType {
        if self.target.apk.is_some() {
            return ArgType::Apk;
        }

        if self.target.xml.is_some() {
            return ArgType::Axml;
        }

        // if self.target.res.is_some() {
        //     return ArgType::Arsc;
        // }

        panic!("Will never happen");
    }

    pub fn get_arg_path(&self) -> PathBuf {
        match self.get_arg_type() {
            ArgType::Apk  => { self.target.apk.clone().unwrap() },
            ArgType::Axml => { self.target.xml.clone().unwrap() },
            ArgType::Arsc => todo!()
        }
    }

    pub fn get_output_path(&self) -> Option<PathBuf> {
        self.output.clone()
    }
}