@@ -3,19 +3,23 @@ use clap::{
33 Parser , Subcommand ,
44} ;
55use luca_pak:: Pak ;
6- use std:: { fs, path:: PathBuf } ;
6+ use std:: { fs, path:: PathBuf , process :: exit } ;
77
88/// Utility to maniuplate PAK archive files from the LUCA System game engine by
99/// Prototype Ltd.
1010#[ derive( Parser ) ]
1111#[ command( name = "PAK Utility" ) ]
12- #[ command( version, about, long_about = None ) ]
12+ #[ command( author , version, about, long_about = None , disable_version_flag = true ) ]
1313struct Cli {
14- #[ arg( value_name = "PAK FILE" ) ]
15- input : PathBuf ,
14+ /// Show program version information
15+ #[ arg( short( 'V' ) , long) ]
16+ version : bool ,
17+
18+ #[ arg( value_name = "PAK FILE" , required_unless_present( "version" ) ) ]
19+ input : Option < PathBuf > ,
1620
1721 #[ command( subcommand) ]
18- command : Commands ,
22+ command : Option < Commands > ,
1923}
2024
2125#[ derive( Subcommand ) ]
@@ -59,12 +63,30 @@ enum Commands {
5963fn main ( ) {
6064 let cli = Cli :: parse ( ) ;
6165
62- let mut pak = match Pak :: open ( & cli. input ) {
66+ if cli. version {
67+ println ! (
68+ "{}, {} v{}-{}" ,
69+ env!( "CARGO_BIN_NAME" ) ,
70+ env!( "CARGO_PKG_NAME" ) ,
71+ env!( "CARGO_PKG_VERSION" ) ,
72+ & env!( "VERGEN_GIT_SHA" ) [ 0 ..=6 ]
73+ ) ;
74+ exit ( 0 ) ;
75+ }
76+
77+ let mut pak = match Pak :: open ( & cli. input . unwrap ( ) ) {
6378 Ok ( pak) => pak,
6479 Err ( err) => fmt_error ( & format ! ( "Could not open PAK file: {}" , err) ) . exit ( ) ,
6580 } ;
6681
67- match cli. command {
82+ let command = match cli. command {
83+ Some ( c) => c,
84+ None => {
85+ exit ( 0 ) ;
86+ } ,
87+ } ;
88+
89+ match command {
6890 Commands :: Extract { output } => {
6991 if output. exists ( ) && !output. is_dir ( ) {
7092 fmt_error ( "The output given was not a directory" ) . exit ( )
@@ -74,7 +96,11 @@ fn main() {
7496
7597 for entry in pak. entries ( ) {
7698 let mut outpath = output. clone ( ) ;
77- outpath. push ( entry. display_name ( ) ) ;
99+ if let Some ( n) = entry. name ( ) {
100+ outpath. push ( n) ;
101+ } else {
102+ outpath. push ( entry. index ( ) . to_string ( ) )
103+ }
78104 entry. save ( & outpath) . unwrap ( ) ;
79105 }
80106 }
0 commit comments