@@ -3,10 +3,10 @@ use rayon::prelude::*;
3
3
use std:: borrow:: Cow ;
4
4
use std:: error:: Error ;
5
5
use std:: fs:: File ;
6
- use std:: io:: { self , Read } ;
6
+ use std:: io:: { self , Read , Write } ;
7
7
8
- const VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
9
- const HELP_MESSAGE : & str = concat ! (
8
+ const VERSION_MESSAGE : & [ u8 ] = concat ! ( "css-inline " , env!( "CARGO_PKG_VERSION" ) , " \n " ) . as_bytes ( ) ;
9
+ const HELP_MESSAGE : & [ u8 ] = concat ! (
10
10
"css-inline " ,
11
11
env!( "CARGO_PKG_VERSION" ) ,
12
12
r#"
@@ -42,12 +42,12 @@ OPTIONS:
42
42
Whether remote stylesheets should be loaded or not.
43
43
44
44
--extra-css
45
- Additional CSS to inline."#
46
- ) ;
45
+ Additional CSS to inline.
46
+ "#
47
+ )
48
+ . as_bytes ( ) ;
47
49
48
50
struct Args {
49
- help : bool ,
50
- version : bool ,
51
51
inline_style_tags : bool ,
52
52
remove_style_tags : bool ,
53
53
base_url : Option < String > ,
@@ -66,24 +66,21 @@ fn parse_url(url: Option<String>) -> Result<Option<url::Url>, url::ParseError> {
66
66
67
67
fn main ( ) -> Result < ( ) , Box < dyn Error > > {
68
68
let mut args = pico_args:: Arguments :: from_env ( ) ;
69
- let args = Args {
70
- help : args. contains ( [ "-h" , "--help" ] ) ,
71
- version : args. contains ( [ "-v" , "--version" ] ) ,
72
- inline_style_tags : args
73
- . opt_value_from_str ( "--inline-style-tags" ) ?
74
- . unwrap_or ( true ) ,
75
- remove_style_tags : args. contains ( "--remove-style-tags" ) ,
76
- base_url : args. opt_value_from_str ( "--base-url" ) ?,
77
- extra_css : args. opt_value_from_str ( "--extra-css" ) ?,
78
- load_remote_stylesheets : args. contains ( "--load-remote-stylesheets" ) ,
79
- files : args. free ( ) ?,
80
- } ;
81
-
82
- if args. help {
83
- println ! ( "{}" , HELP_MESSAGE )
84
- } else if args. version {
85
- println ! ( "css-inline {}" , VERSION )
69
+ if args. contains ( [ "-h" , "--help" ] ) {
70
+ io:: stdout ( ) . write_all ( HELP_MESSAGE ) ?;
71
+ } else if args. contains ( [ "-v" , "--version" ] ) {
72
+ io:: stdout ( ) . write_all ( VERSION_MESSAGE ) ?;
86
73
} else {
74
+ let args = Args {
75
+ inline_style_tags : args
76
+ . opt_value_from_str ( "--inline-style-tags" ) ?
77
+ . unwrap_or ( true ) ,
78
+ remove_style_tags : args. contains ( "--remove-style-tags" ) ,
79
+ base_url : args. opt_value_from_str ( "--base-url" ) ?,
80
+ extra_css : args. opt_value_from_str ( "--extra-css" ) ?,
81
+ load_remote_stylesheets : args. contains ( "--load-remote-stylesheets" ) ,
82
+ files : args. free ( ) ?,
83
+ } ;
87
84
let options = InlineOptions {
88
85
inline_style_tags : args. inline_style_tags ,
89
86
remove_style_tags : args. remove_style_tags ,
0 commit comments