@@ -69,6 +69,7 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
69
69
opts. index . clone ( ) ,
70
70
opts. registry . clone ( ) ,
71
71
true ,
72
+ !opts. dry_run
72
73
) ?;
73
74
verify_dependencies ( pkg, & registry, reg_id) ?;
74
75
@@ -334,12 +335,13 @@ pub fn registry_configuration(
334
335
Ok ( RegistryConfig { index, token } )
335
336
}
336
337
337
- pub fn registry (
338
+ fn registry (
338
339
config : & Config ,
339
340
token : Option < String > ,
340
341
index : Option < String > ,
341
342
registry : Option < String > ,
342
343
force_update : bool ,
344
+ validate_token : bool
343
345
) -> CargoResult < ( Registry , SourceId ) > {
344
346
// Parse all configuration options
345
347
let RegistryConfig {
@@ -363,6 +365,9 @@ pub fn registry(
363
365
. ok_or_else ( || format_err ! ( "{} does not support API commands" , sid) ) ?
364
366
} ;
365
367
let handle = http_handle ( config) ?;
368
+ if validate_token && token. is_none ( ) {
369
+ bail ! ( "no upload token found, please run `cargo login`" ) ;
370
+ } ;
366
371
Ok ( ( Registry :: new_handle ( api_host, token, handle) , sid) )
367
372
}
368
373
@@ -536,7 +541,7 @@ pub fn registry_login(
536
541
token : Option < String > ,
537
542
reg : Option < String > ,
538
543
) -> CargoResult < ( ) > {
539
- let ( registry, _) = registry ( config, token. clone ( ) , None , reg. clone ( ) , false ) ?;
544
+ let ( registry, _) = registry ( config, token. clone ( ) , None , reg. clone ( ) , false , false ) ?;
540
545
541
546
let token = match token {
542
547
Some ( token) => token,
@@ -604,6 +609,7 @@ pub fn modify_owners(config: &Config, opts: &OwnersOptions) -> CargoResult<()> {
604
609
opts. index . clone ( ) ,
605
610
opts. registry . clone ( ) ,
606
611
true ,
612
+ true
607
613
) ?;
608
614
609
615
if let Some ( ref v) = opts. to_add {
@@ -664,7 +670,7 @@ pub fn yank(
664
670
None => bail ! ( "a version must be specified to yank" ) ,
665
671
} ;
666
672
667
- let ( mut registry, _) = registry ( config, token, index, reg, true ) ?;
673
+ let ( mut registry, _) = registry ( config, token, index, reg, true , true ) ?;
668
674
669
675
if undo {
670
676
config
@@ -720,7 +726,7 @@ pub fn search(
720
726
prefix
721
727
}
722
728
723
- let ( mut registry, source_id) = registry ( config, None , index, reg, false ) ?;
729
+ let ( mut registry, source_id) = registry ( config, None , index, reg, false , false ) ?;
724
730
let ( crates, total_crates) = registry
725
731
. search ( query, limit)
726
732
. chain_err ( || "failed to retrieve search results from the registry" ) ?;
0 commit comments