21
21
import os
22
22
import sys
23
23
import click
24
+ import logging
24
25
25
26
from cloe_launch .exec import Engine
26
27
from cloe_launch import Configuration , ConfigurationError
38
39
def main (ctx , verbose : int ):
39
40
"""Launch cloe-engine with profiles and manage launch profiles."""
40
41
42
+ if verbose == 0 :
43
+ level = logging .WARNING
44
+ elif verbose == 1 :
45
+ level = logging .INFO
46
+ else :
47
+ level = logging .DEBUG
48
+ logging .basicConfig (format = "%(message)s" , stream = sys .stderr , level = level )
49
+
41
50
class Options :
42
51
def __init__ (self , verbose ):
43
52
self .verbose = verbose
44
53
45
- ctx .obj = Options (verbose = verbose )
54
+ ctx .obj = Options (verbose > 0 )
46
55
47
56
48
57
# Common options among engine and profile commands:
@@ -130,7 +139,7 @@ def cli_exec(
130
139
ENGINE_ARGS are passed on to cloe-engine.
131
140
"""
132
141
deny_profile_and_path (profile , profile_path )
133
- conf = Configuration (profile , opt . verbose )
142
+ conf = Configuration (profile )
134
143
engine = Engine (conf , conanfile = profile_path )
135
144
engine .preserve_env = preserve_env
136
145
engine .conan_options = conan_option
@@ -178,7 +187,7 @@ def cli_shell(
178
187
) -> None :
179
188
"""Launch shell with the correct environment from a profile."""
180
189
deny_profile_and_path (profile , profile_path )
181
- conf = Configuration (profile , opt . verbose )
190
+ conf = Configuration (profile )
182
191
engine = Engine (conf , conanfile = profile_path )
183
192
engine .preserve_env = preserve_env
184
193
engine .conan_options = conan_option
@@ -196,7 +205,7 @@ def cli_shell(
196
205
def cli_clean (opt , profile : str , profile_path : str ) -> None :
197
206
"""Clean launcher profile cache."""
198
207
deny_profile_and_path (profile , profile_path )
199
- conf = Configuration (profile , opt . verbose )
208
+ conf = Configuration (profile )
200
209
engine = Engine (conf , conanfile = profile_path )
201
210
engine .clean ()
202
211
@@ -215,7 +224,7 @@ def cli_profile():
215
224
@click .pass_obj
216
225
def cli_profile_show (opt , profile : str ) -> None :
217
226
"""Show a profile configuration."""
218
- conf = Configuration (profile , opt . verbose )
227
+ conf = Configuration (profile )
219
228
if conf .current_profile is None :
220
229
raise ConfigurationError ("no default profile is configured" )
221
230
data = conf .read (conf .current_profile )
@@ -228,9 +237,9 @@ def cli_profile_show(opt, profile: str) -> None:
228
237
@click .pass_obj
229
238
def cli_profile_list (opt ) -> None :
230
239
"""List all available profiles."""
231
- conf = Configuration (verbose = opt . verbose )
240
+ conf = Configuration ()
232
241
for profile in conf .all_profiles :
233
- if opt .verbose > 0 :
242
+ if opt .verbose :
234
243
if profile == conf .default_profile :
235
244
print ("*" , profile )
236
245
else :
@@ -253,7 +262,7 @@ def cli_profile_add(
253
262
opt , profile : str , conanfile : str , force : bool = False , default : bool = False
254
263
) -> None :
255
264
"""Add a new profile."""
256
- conf = Configuration (verbose = opt . verbose )
265
+ conf = Configuration ()
257
266
conf .add (profile , conanfile , force = force )
258
267
if default :
259
268
conf .set_default (profile )
@@ -279,7 +288,7 @@ def cli_profile_add(
279
288
@click .pass_obj
280
289
def cli_profile_edit (opt , profile : str , editor : str , create : bool ) -> None :
281
290
"""Edit a profile."""
282
- conf = Configuration (profile , verbose = opt . verbose )
291
+ conf = Configuration (profile )
283
292
if conf .current_profile is None :
284
293
raise ConfigurationError ("no default profile is configured" )
285
294
conf .edit (conf .current_profile , create )
@@ -292,7 +301,7 @@ def cli_profile_edit(opt, profile: str, editor: str, create: bool) -> None:
292
301
@click .pass_obj
293
302
def cli_profile_remove (opt , profile : str ) -> None :
294
303
"""Remove a profile."""
295
- conf = Configuration (verbose = opt . verbose )
304
+ conf = Configuration ()
296
305
conf .remove (profile )
297
306
298
307
@@ -303,11 +312,11 @@ def cli_profile_remove(opt, profile: str) -> None:
303
312
@click .pass_obj
304
313
def cli_profile_default (opt , profile : str ) -> None :
305
314
"""Show or set the default profile."""
306
- conf = Configuration (profile , verbose = opt . verbose )
315
+ conf = Configuration (profile )
307
316
if profile is None :
308
317
if conf .default_profile is not None :
309
318
print (conf .default_profile )
310
- elif opt .verbose > 0 :
319
+ elif opt .verbose :
311
320
print ("Note: no default profile is configured" )
312
321
else :
313
322
# Set default to provided value, which must exist already
0 commit comments