1
+ use std:: path:: PathBuf ;
2
+
1
3
use clap:: ArgAction ;
2
4
use clap_verbosity_flag:: { ErrorLevel , Verbosity } ;
3
5
4
6
use clap:: Parser ;
7
+ use rattler_conda_types:: Platform ;
5
8
6
9
#[ derive( Parser , Debug ) ]
7
10
#[ command( name = "conda-deny" , about = "Check and list licenses of pixi and conda environments" , version = env!( "CARGO_PKG_VERSION" ) ) ]
@@ -10,94 +13,130 @@ pub struct Cli {
10
13
pub verbose : Verbosity < ErrorLevel > ,
11
14
12
15
#[ command( subcommand) ]
13
- pub command : Commands ,
16
+ pub command : CondaDenyCliConfig ,
14
17
18
+ /// Path to the conda-deny config file
15
19
#[ arg( short, long, global = true ) ]
16
- pub config : Option < String > ,
17
-
18
- #[ arg( long, global = true ) ]
19
- pub prefix : Option < Vec < String > > ,
20
-
21
- #[ arg( short, long) ]
22
- pub lockfile : Option < Vec < String > > ,
23
-
24
- #[ arg( short, long) ]
25
- pub platform : Option < Vec < String > > ,
26
-
27
- #[ arg( short, long) ]
28
- pub environment : Option < Vec < String > > ,
20
+ pub config : Option < PathBuf > ,
29
21
}
30
22
31
23
#[ derive( clap:: Subcommand , Debug ) ]
32
- pub enum Commands {
24
+ pub enum CondaDenyCliConfig {
33
25
Check {
34
- #[ arg( short, long, action = ArgAction :: SetTrue ) ]
35
- include_safe : bool ,
26
+ /// Path to the pixi lockfile(s)
27
+ #[ arg( short, long) ]
28
+ lockfile : Option < Vec < PathBuf > > ,
36
29
30
+ /// Path to the conda prefix(es)
31
+ #[ arg( long, global = true ) ]
32
+ prefix : Option < Vec < PathBuf > > ,
33
+
34
+ /// Platform(s) to check
35
+ #[ arg( short, long) ]
36
+ platform : Option < Vec < Platform > > ,
37
+
38
+ /// Pixi environment(s) to check
39
+ #[ arg( short, long) ]
40
+ environment : Option < Vec < String > > ,
41
+
42
+ /// Check against OSI licenses instead of custom license whitelists.
37
43
#[ arg( short, long, action = ArgAction :: SetTrue ) ]
38
- osi : bool ,
44
+ osi : Option < bool > ,
39
45
40
46
/// Ignore when encountering pypi packages instead of failing.
41
47
#[ arg( long, action = ArgAction :: SetTrue ) ]
42
- ignore_pypi : bool ,
48
+ ignore_pypi : Option < bool > ,
49
+ } ,
50
+ List {
51
+ /// Path to the pixi lockfile(s)
52
+ #[ arg( short, long) ]
53
+ lockfile : Option < Vec < PathBuf > > ,
54
+
55
+ /// Path to the conda prefix(es)
56
+ #[ arg( long, global = true ) ]
57
+ prefix : Option < Vec < PathBuf > > ,
58
+
59
+ /// Platform(s) to list
60
+ #[ arg( short, long) ]
61
+ platform : Option < Vec < Platform > > ,
62
+
63
+ /// Pixi environment(s) to list
64
+ #[ arg( short, long) ]
65
+ environment : Option < Vec < String > > ,
66
+
67
+ /// Ignore when encountering pypi packages instead of failing.
68
+ #[ arg( long) ]
69
+ ignore_pypi : Option < bool > ,
43
70
} ,
44
- List { } ,
45
71
}
46
72
47
- #[ cfg( test) ]
48
- mod tests {
49
- use super :: * ;
73
+ impl CondaDenyCliConfig {
74
+ pub fn lockfile ( & self ) -> Option < Vec < PathBuf > > {
75
+ match self {
76
+ CondaDenyCliConfig :: Check { lockfile, .. } => lockfile. clone ( ) ,
77
+ CondaDenyCliConfig :: List { lockfile, .. } => lockfile. clone ( ) ,
78
+ }
79
+ }
50
80
51
- #[ test]
52
- fn test_cli_check_include_safe ( ) {
53
- let cli = Cli :: try_parse_from ( vec ! [ "conda-deny" , "check" , "--include-safe" ] ) . unwrap ( ) ;
54
- match cli. command {
55
- Commands :: Check { include_safe, .. } => {
56
- assert ! ( include_safe) ;
57
- }
58
- _ => panic ! ( "Expected check subcommand with --include-safe" ) ,
81
+ pub fn prefix ( & self ) -> Option < Vec < PathBuf > > {
82
+ match self {
83
+ CondaDenyCliConfig :: Check { prefix, .. } => prefix. clone ( ) ,
84
+ CondaDenyCliConfig :: List { prefix, .. } => prefix. clone ( ) ,
59
85
}
60
86
}
61
87
88
+ pub fn platform ( & self ) -> Option < Vec < Platform > > {
89
+ match self {
90
+ CondaDenyCliConfig :: Check { platform, .. } => platform. clone ( ) ,
91
+ CondaDenyCliConfig :: List { platform, .. } => platform. clone ( ) ,
92
+ }
93
+ }
94
+
95
+ pub fn environment ( & self ) -> Option < Vec < String > > {
96
+ match self {
97
+ CondaDenyCliConfig :: Check { environment, .. } => environment. clone ( ) ,
98
+ CondaDenyCliConfig :: List { environment, .. } => environment. clone ( ) ,
99
+ }
100
+ }
101
+
102
+ pub fn ignore_pypi ( & self ) -> Option < bool > {
103
+ match self {
104
+ CondaDenyCliConfig :: Check { ignore_pypi, .. } => * ignore_pypi,
105
+ CondaDenyCliConfig :: List { ignore_pypi, .. } => * ignore_pypi,
106
+ }
107
+ }
108
+ }
109
+
110
+ #[ cfg( test) ]
111
+ mod tests {
112
+ use super :: * ;
113
+
62
114
#[ test]
63
115
fn test_cli_with_config ( ) {
64
116
let cli =
65
117
Cli :: try_parse_from ( vec ! [ "conda-deny" , "list" , "--config" , "custom.toml" ] ) . unwrap ( ) ;
66
- assert_eq ! ( cli. config. as_deref ( ) , Some ( "custom.toml" ) ) ;
118
+ assert_eq ! ( cli. config, Some ( "custom.toml" . into ( ) ) ) ;
67
119
}
68
120
69
121
#[ test]
70
122
fn test_cli_with_config_new_order ( ) {
71
123
let cli =
72
124
Cli :: try_parse_from ( vec ! [ "conda-deny" , "check" , "--config" , "custom.toml" ] ) . unwrap ( ) ;
73
- assert_eq ! ( cli. config. as_deref ( ) , Some ( "custom.toml" ) ) ;
125
+ assert_eq ! ( cli. config, Some ( "custom.toml" . into ( ) ) ) ;
74
126
match cli. command {
75
- Commands :: Check { include_safe, .. } => {
76
- assert ! ( !include_safe) ;
77
- }
127
+ CondaDenyCliConfig :: Check { .. } => { }
78
128
_ => panic ! ( "Expected check subcommand with --config" ) ,
79
129
}
80
130
}
81
131
82
132
#[ test]
83
133
fn test_cli_with_check_arguments ( ) {
84
- let cli = Cli :: try_parse_from ( vec ! [ "conda-deny" , "check" , "--include-safe" ] ) . unwrap ( ) ;
85
- match cli. command {
86
- Commands :: Check { include_safe, .. } => {
87
- assert ! ( include_safe) ;
88
- }
89
- _ => panic ! ( "Expected check subcommand with --include-safe" ) ,
90
- }
91
- }
92
-
93
- #[ test]
94
- fn test_cli_with_check_osi ( ) {
95
134
let cli = Cli :: try_parse_from ( vec ! [ "conda-deny" , "check" , "--osi" ] ) . unwrap ( ) ;
96
135
match cli. command {
97
- Commands :: Check { osi, .. } => {
98
- assert ! ( osi) ;
136
+ CondaDenyCliConfig :: Check { osi, .. } => {
137
+ assert_eq ! ( osi, Some ( true ) ) ;
99
138
}
100
- _ => panic ! ( "Expected check subcommand with --osi " ) ,
139
+ _ => panic ! ( "Expected check subcommand with --include-safe " ) ,
101
140
}
102
141
}
103
142
}
0 commit comments