@@ -6,8 +6,8 @@ use crate::package::Package;
6
6
use clap:: Parser ;
7
7
use config_file:: ConfigFile ;
8
8
use std:: env:: current_dir;
9
- use std:: fs:: { create_dir, read_dir, remove_dir} ;
10
- use std:: io:: Result ;
9
+ use std:: fs:: { create_dir, read_dir, remove_dir, write } ;
10
+ use std:: io:: { stdin , Read , Result } ;
11
11
use std:: panic;
12
12
use std:: path:: { Path , PathBuf } ;
13
13
@@ -24,15 +24,15 @@ struct Args {
24
24
default_value = "godot.package" ,
25
25
global = true
26
26
) ]
27
- /// Specify the location of the package configuration file (https://github.com/godot-package-manager#godotpackage).
27
+ /// Specify the location of the package configuration file (https://github.com/godot-package-manager#godotpackage). If -, read from stdin.
28
28
config_file : PathBuf ,
29
29
#[ arg(
30
30
short = 'l' ,
31
31
long = "lock-file" ,
32
32
default_value = "godot.lock" ,
33
33
global = true
34
34
) ]
35
- /// Specify the location of the lock file
35
+ /// Specify the location of the lock file. If -, print to stdout.
36
36
lock_file : PathBuf ,
37
37
}
38
38
@@ -68,14 +68,30 @@ fn main() {
68
68
else { println ! ( "unknown" ) ; } ;
69
69
} ) ) ;
70
70
let args = Args :: parse ( ) ;
71
- let mut cfg_file = ConfigFile :: new ( args. config_file ) ;
71
+ let mut contents = String :: from ( "" ) ;
72
+ if args. config_file == Path :: new ( "-" ) {
73
+ let bytes = stdin ( )
74
+ . read_to_string ( & mut contents)
75
+ . expect ( "Stdin read should be ok" ) ;
76
+ if bytes == 0 {
77
+ panic ! ( "Stdin should not be empty" ) ;
78
+ } ;
79
+ } else {
80
+ contents =
81
+ std:: fs:: read_to_string ( args. config_file ) . expect ( "Reading config file should be ok" ) ;
82
+ } ;
83
+ let mut cfg_file = ConfigFile :: new ( & contents) ;
72
84
match args. action {
73
85
Actions :: Update => update ( & mut cfg_file) ,
74
86
Actions :: Purge => purge ( & mut cfg_file) ,
75
87
Actions :: Tree => tree ( & cfg_file) ,
76
88
}
77
- cfg_file. lock ( args. lock_file ) ;
78
- println ! ( "Finished" ) ;
89
+ let lockfile = cfg_file. lock ( ) ;
90
+ if args. lock_file == Path :: new ( "-" ) {
91
+ println ! ( "{lockfile}" ) ;
92
+ } else {
93
+ write ( args. lock_file , lockfile) . expect ( "Writing lock file should be ok" ) ;
94
+ }
79
95
}
80
96
81
97
fn update ( cfg : & mut ConfigFile ) {
0 commit comments