Skip to content

Commit

Permalink
made command output a tad nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
nesium committed Aug 29, 2019
1 parent 9694fd4 commit bd6f119
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 14 deletions.
57 changes: 56 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion xcode-color-assets/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[package]
name = "xcode-color-assets"
version = "0.3.1"
version = "0.3.2"
authors = ["mb <[email protected]>"]
edition = "2018"
description = "Create (dark mode compatible) color assets for Xcode programmatically from a CSS-like textfile"

[dependencies]
clap = "2.33"
colored = "1.8"
parser = { path = "../parser" }
asset-catalog = { path = "../asset-catalog" }
swift-gen = { path = "../swift-gen" }
41 changes: 29 additions & 12 deletions xcode-color-assets/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
use asset_catalog::{write_asset_catalog, ColorSpace};
use clap::{App, Arg, SubCommand};
use clap::{crate_description, crate_name, crate_version, App, AppSettings, Arg, SubCommand};
use colored::*;
use parser::parse_document_from_file;
use std::path::Path;
use std::str::FromStr;
use swift_gen::gen_swift;

fn main() {
let matches = App::new("xcode-color-assets")
.version("0.3.1")
.about("Create Xcode Asset Catalog with colors for light & dark mode.")
let matches = App::new(crate_name!())
.version(crate_version!())
.about(crate_description!())
.global_setting(AppSettings::ColorAuto)
.global_setting(AppSettings::ColoredHelp)
.global_setting(AppSettings::DeriveDisplayOrder)
.global_setting(AppSettings::UnifiedHelpMessage)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("gen-assets")
.about("generates the Asset Catalog")
Expand Down Expand Up @@ -76,7 +82,7 @@ fn main() {
let doc = match parse_document_from_file(&input_file) {
Ok(doc) => doc,
Err(e) => {
println!("{}", e);
println!("{}", format!("{}", e).red());
std::process::exit(0x0100);
}
};
Expand All @@ -91,16 +97,23 @@ fn main() {
) {
Err(asset_catalog::Error::CatalogExists(_)) => {
println!(
"Asset catalog at {} already exists. Use -f to overwrite it.",
output_path
"{}",
format!(
"Asset catalog at {} already exists. Use -f to overwrite it.",
output_path
)
.yellow()
);
std::process::exit(0x0100);
}
Err(e) => {
println!("{}", e);
println!("{}", format!("{}", e).red());
std::process::exit(0x0100);
}
Ok(_) => println!("Generated Asset catalog at {}.", output_path),
Ok(_) => println!(
"{}",
format!("Generated Asset catalog at {}.", output_path).green()
),
}
}
("gen-swift", Some(m)) => {
Expand All @@ -110,17 +123,21 @@ fn main() {
let doc = match parse_document_from_file(&input_file) {
Ok(doc) => doc,
Err(e) => {
println!("{}", e);
println!("{}", format!("{}", e).red());
std::process::exit(0x0100);
}
};

match gen_swift(&doc, &Path::new(output_path), false) {
Err(e @ swift_gen::Error::FileIsIdentical(_)) => println!("{}", format!("{}", e).dimmed()),
Err(e) => {
println!("{}", e);
println!("{}", format!("{}", e).red());
std::process::exit(0x0100);
}
Ok(_) => println!("Generated Swift file at {}.", output_path),
Ok(_) => println!(
"{}",
format!("Generated Swift file at {}.", output_path).green()
),
}
}
(&_, _) => {}
Expand Down

0 comments on commit bd6f119

Please sign in to comment.