@@ -8,10 +8,11 @@ use anyhow::{bail, Context, Error};
8
8
use clap:: Parser ;
9
9
use console:: style;
10
10
11
+ use crate :: config:: Config ;
11
12
use crate :: pyproject:: { PyProject , Script } ;
12
- use crate :: sync:: { sync, SyncOptions } ;
13
+ use crate :: sync:: { autosync , sync, SyncOptions } ;
13
14
use crate :: tui:: redirect_to_stderr;
14
- use crate :: utils:: { exec_spawn, get_venv_python_bin, success_status, IoPathContext } ;
15
+ use crate :: utils:: { exec_spawn, get_venv_python_bin, success_status, CommandOutput , IoPathContext } ;
15
16
16
17
/// Runs a command installed into this package.
17
18
#[ derive( Parser , Debug ) ]
@@ -26,6 +27,18 @@ pub struct Args {
26
27
/// Use this pyproject.toml file
27
28
#[ arg( long, value_name = "PYPROJECT_TOML" ) ]
28
29
pyproject : Option < PathBuf > ,
30
+ /// Runs `sync` even if auto-sync is disabled.
31
+ #[ arg( long) ]
32
+ sync : bool ,
33
+ /// Does not run `sync` even if auto-sync is enabled.
34
+ #[ arg( long, conflicts_with = "sync" ) ]
35
+ no_sync : bool ,
36
+ /// Enables verbose diagnostics.
37
+ #[ arg( short, long) ]
38
+ verbose : bool ,
39
+ /// Turns off all output.
40
+ #[ arg( short, long, conflicts_with = "verbose" ) ]
41
+ quiet : bool ,
29
42
}
30
43
31
44
#[ derive( Parser , Debug ) ]
@@ -36,11 +49,16 @@ enum Cmd {
36
49
37
50
pub fn execute ( cmd : Args ) -> Result < ( ) , Error > {
38
51
let _guard = redirect_to_stderr ( true ) ;
52
+ let output = CommandOutput :: from_quiet_and_verbose ( cmd. quiet , cmd. verbose ) ;
39
53
let pyproject = PyProject :: load_or_discover ( cmd. pyproject . as_deref ( ) ) ?;
40
54
41
- // make sure we have the minimal virtualenv.
42
- sync ( SyncOptions :: python_only ( ) . pyproject ( cmd. pyproject ) )
43
- . context ( "failed to sync ahead of run" ) ?;
55
+ if ( Config :: current ( ) . autosync_before_run ( ) && !cmd. no_sync ) || cmd. sync {
56
+ autosync ( & pyproject, output, true ) ?;
57
+ } else {
58
+ // make sure we have the minimal virtualenv.
59
+ sync ( SyncOptions :: python_only ( ) . pyproject ( cmd. pyproject ) )
60
+ . context ( "failed to sync ahead of run" ) ?;
61
+ }
44
62
45
63
if cmd. list || cmd. cmd . is_none ( ) {
46
64
return list_scripts ( & pyproject) ;
0 commit comments