|
1 | 1 | mod asset_catalog; |
2 | 2 | mod ast; |
| 3 | +mod gen_swift; |
3 | 4 | mod parser; |
4 | 5 |
|
5 | 6 | use crate::asset_catalog::write_asset_catalog; |
| 7 | +use crate::gen_swift::gen_swift; |
6 | 8 | use crate::parser::parse_document_from_file; |
7 | | -use clap::{App, Arg}; |
| 9 | +use clap::{App, Arg, SubCommand}; |
8 | 10 |
|
9 | 11 | fn main() { |
10 | 12 | let matches = App::new("color-assets") |
11 | 13 | .version("1.0") |
12 | 14 | .about("Create Xcode Asset Catalog with colors for light & dark mode.") |
13 | | - .arg( |
14 | | - Arg::with_name("output") |
15 | | - .short("o") |
16 | | - .help("Sets the output filename") |
17 | | - .value_name("OUTPUT_FILE") |
18 | | - .required(true), |
| 15 | + .subcommand( |
| 16 | + SubCommand::with_name("gen-assets") |
| 17 | + .about("generates the Asset Catalog") |
| 18 | + .arg( |
| 19 | + Arg::with_name("output") |
| 20 | + .short("o") |
| 21 | + .help("Sets the output filename (e.g. Colors.xcassets)") |
| 22 | + .value_name("OUTPUT_FILE") |
| 23 | + .required(true), |
| 24 | + ) |
| 25 | + .arg( |
| 26 | + Arg::with_name("input") |
| 27 | + .help("Sets the input file") |
| 28 | + .value_name("INPUT_FILE") |
| 29 | + .required(true) |
| 30 | + .index(1), |
| 31 | + ), |
19 | 32 | ) |
20 | | - .arg( |
21 | | - Arg::with_name("input") |
22 | | - .help("Sets the input file") |
23 | | - .value_name("INPUT_FILE") |
24 | | - .required(true) |
25 | | - .index(1), |
| 33 | + .subcommand( |
| 34 | + SubCommand::with_name("gen-swift") |
| 35 | + .about("generates Swift code") |
| 36 | + .arg( |
| 37 | + Arg::with_name("output") |
| 38 | + .short("o") |
| 39 | + .help("Sets the output filename (e.g. Colors.swift)") |
| 40 | + .value_name("OUTPUT_FILE") |
| 41 | + .required(true), |
| 42 | + ) |
| 43 | + .arg( |
| 44 | + Arg::with_name("input") |
| 45 | + .help("Sets the input file") |
| 46 | + .value_name("INPUT_FILE") |
| 47 | + .required(true) |
| 48 | + .index(1), |
| 49 | + ), |
26 | 50 | ) |
27 | 51 | .get_matches(); |
28 | 52 |
|
29 | | - let input_file = matches.value_of("input").unwrap(); |
30 | | - let output_path = matches.value_of("output").unwrap(); |
31 | | - |
32 | | - let doc = parse_document_from_file(&input_file).expect("Could not parse input file."); |
33 | | - write_asset_catalog(&doc, &output_path).expect("Could not write asset catalog."); |
| 53 | + match matches.subcommand() { |
| 54 | + ("gen-assets", Some(m)) => { |
| 55 | + let input_file = m.value_of("input").unwrap(); |
| 56 | + let output_path = m.value_of("output").unwrap(); |
| 57 | + let doc = parse_document_from_file(&input_file).expect("Could not parse input file."); |
| 58 | + write_asset_catalog(&doc, &output_path).expect("Could not write asset catalog."); |
| 59 | + } |
| 60 | + ("gen-swift", Some(m)) => { |
| 61 | + let input_file = m.value_of("input").unwrap(); |
| 62 | + let output_path = m.value_of("output").unwrap(); |
| 63 | + let doc = parse_document_from_file(&input_file).expect("Could not parse input file."); |
| 64 | + gen_swift(&doc, &output_path).expect("Could not generate Swift code."); |
| 65 | + } |
| 66 | + (&_, _) => {} |
| 67 | + } |
34 | 68 | } |
35 | 69 |
|
36 | 70 | #[cfg(test)] |
|
0 commit comments