17
17
//! cd implementations/rust/ockam/ockam_command && cargo install --path .
18
18
//! ```
19
19
20
+ use std:: process:: exit;
20
21
use std:: { path:: PathBuf , sync:: Mutex } ;
21
22
22
23
use clap:: { ArgAction , Args , Parser , Subcommand } ;
@@ -70,7 +71,7 @@ use crate::kafka::direct::KafkaDirectCommand;
70
71
use crate :: kafka:: outlet:: KafkaOutletCommand ;
71
72
use crate :: logs:: setup_logging;
72
73
use crate :: node:: NodeSubcommand ;
73
- use crate :: output:: { Output , OutputFormat } ;
74
+ use crate :: output:: OutputFormat ;
74
75
use crate :: run:: RunCommand ;
75
76
use crate :: sidecar:: SidecarCommand ;
76
77
use crate :: subscription:: SubscriptionCommand ;
@@ -242,30 +243,22 @@ pub struct CommandGlobalOpts {
242
243
243
244
impl CommandGlobalOpts {
244
245
pub fn new ( global_args : GlobalArgs ) -> Self {
246
+ let terminal = Terminal :: from ( & global_args) ;
245
247
let state = match CliState :: with_default_dir ( ) {
246
248
Ok ( state) => state,
247
- Err ( err) => {
248
- eprintln ! ( "Failed to initialize state: {}" , err) ;
249
- if std:: env:: var ( "OCKAM_NO_AUTOMATIC_RESET" ) . is_ok ( ) {
250
- std:: process:: exit ( exitcode:: CONFIG ) ;
251
- }
252
- let state = CliState :: backup_and_reset ( ) . expect (
253
- "Failed to initialize CliState. Try to manually remove the '~/.ockam' directory" ,
254
- ) ;
255
- let dir = state. dir ( ) ;
256
- let backup_dir = CliState :: backup_default_dir ( ) . unwrap ( ) ;
257
- eprintln ! (
258
- "The {dir:?} directory has been reset and has been backed up to {backup_dir:?}"
259
- ) ;
260
- state
249
+ Err ( _) => {
250
+ terminal
251
+ . write_line ( fmt_err ! ( "Failed to initialize local state" ) )
252
+ . unwrap ( ) ;
253
+ terminal
254
+ . write_line ( fmt_log ! (
255
+ "Consider upgrading to the latest version of Ockam Command, \
256
+ or try removing the local state directory at ~/.ockam"
257
+ ) )
258
+ . unwrap ( ) ;
259
+ exit ( exitcode:: SOFTWARE ) ;
261
260
}
262
261
} ;
263
- let terminal = Terminal :: new (
264
- global_args. quiet ,
265
- global_args. no_color ,
266
- global_args. no_input ,
267
- global_args. output_format . clone ( ) ,
268
- ) ;
269
262
Self {
270
263
global_args,
271
264
state,
@@ -279,15 +272,6 @@ impl CommandGlobalOpts {
279
272
clone. terminal = clone. terminal . set_quiet ( ) ;
280
273
clone
281
274
}
282
-
283
- /// Print a value on the console.
284
- /// TODO: replace this implementation with a call to the terminal instead
285
- pub fn println < T > ( & self , t : & T ) -> Result < ( ) >
286
- where
287
- T : Output + serde:: Serialize ,
288
- {
289
- self . global_args . output_format . println_value ( t)
290
- }
291
275
}
292
276
293
277
#[ cfg( test) ]
@@ -374,10 +358,7 @@ pub fn run() {
374
358
375
359
match OckamCommand :: try_parse_from ( input) {
376
360
Ok ( command) => {
377
- if !command. global_args . test_argument_parser {
378
- check_if_an_upgrade_is_available ( ) ;
379
- }
380
-
361
+ check_if_an_upgrade_is_available ( & command. global_args ) ;
381
362
command. run ( ) ;
382
363
}
383
364
Err ( help) => pager:: render_help ( help) ,
0 commit comments