File tree Expand file tree Collapse file tree 5 files changed +31
-15
lines changed
Expand file tree Collapse file tree 5 files changed +31
-15
lines changed Original file line number Diff line number Diff line change 1- use crate :: fetcher:: Fetcher ;
21use crate :: version:: { NodeVersion , Version } ;
32use crate :: { config:: Config , downloader:: Downloader } ;
3+ use crate :: { fetcher:: Fetcher , progress_bar:: Spinner } ;
44use clap:: Clap ;
55use colored:: * ;
66
@@ -23,6 +23,8 @@ impl super::Command for Install {
2323 ) ;
2424 }
2525
26+ let spnr = Spinner :: fetch ( ) ;
27+
2628 let ( release, is_lts) = match & self . version {
2729 Version :: Full ( NodeVersion :: Lts ( lts) ) => {
2830 ( Fetcher :: fetch ( & config. dist_mirror ) ?. lts_name ( lts) , true )
@@ -37,7 +39,7 @@ impl super::Command for Install {
3739 Some ( r) => {
3840 let dwnld = Downloader :: new ( & r, & config) ;
3941
40- let dest = dwnld. download ( ) ?;
42+ let dest = dwnld. download ( & spnr ) ?;
4143
4244 if is_lts {
4345 let alias = self . version . to_string ( ) ;
@@ -51,10 +53,14 @@ impl super::Command for Install {
5153
5254 Ok ( ( ) )
5355 }
54- _ => anyhow:: bail!(
55- "No release found with the version {}" ,
56- & self . version. to_string( ) . bold( )
57- ) ,
56+ _ => {
57+ spnr. stop ( ) ;
58+
59+ anyhow:: bail!(
60+ "No release found with the version {}" ,
61+ & self . version. to_string( ) . bold( )
62+ ) ;
63+ }
5864 }
5965 }
6066}
Original file line number Diff line number Diff line change 1- use crate :: fetcher:: Fetcher ;
21use crate :: { config:: Config , downloader:: Downloader } ;
2+ use crate :: { fetcher:: Fetcher , progress_bar:: Spinner } ;
33use clap:: Clap ;
44use colored:: * ;
55
@@ -12,11 +12,13 @@ impl super::Command for Latest {
1212 type InitResult = ( ) ;
1313
1414 fn init ( & self , config : Config ) -> anyhow:: Result < Self :: InitResult > {
15+ let spnr = Spinner :: fetch ( ) ;
16+
1517 let releases = Fetcher :: fetch ( & config. dist_mirror ) ?;
1618 let release = releases. latest ( ) ?;
1719
1820 let dwnld = Downloader :: new ( release, & config) ;
19- let dest = dwnld. download ( ) ?;
21+ let dest = dwnld. download ( & spnr ) ?;
2022
2123 crate :: symlink:: symlink_to ( & dest, & config. alias_dir ( ) . join ( & ALIAS ) ) ?;
2224
Original file line number Diff line number Diff line change 1- use crate :: fetcher:: Fetcher ;
21use crate :: { config:: Config , downloader:: Downloader } ;
2+ use crate :: { fetcher:: Fetcher , progress_bar:: Spinner } ;
33use clap:: Clap ;
44use colored:: * ;
55
@@ -12,11 +12,13 @@ impl super::Command for Lts {
1212 type InitResult = ( ) ;
1313
1414 fn init ( & self , config : Config ) -> anyhow:: Result < Self :: InitResult > {
15+ let spnr = Spinner :: fetch ( ) ;
16+
1517 let releases = Fetcher :: fetch ( & config. dist_mirror ) ?;
1618 let release = releases. lts ( ) ?;
1719
1820 let dwnld = Downloader :: new ( release, & config) ;
19- let dest = dwnld. download ( ) ?;
21+ let dest = dwnld. download ( & spnr ) ?;
2022
2123 crate :: symlink:: symlink_to ( & dest, & config. alias_dir ( ) . join ( & ALIAS ) ) ?;
2224
Original file line number Diff line number Diff line change 1- use crate :: fetcher:: Release ;
21use crate :: symlink:: symlink_to;
32use crate :: { archive:: Archive , progress_bar:: Bar } ;
43use crate :: { config:: Config , url} ;
4+ use crate :: { fetcher:: Release , progress_bar:: Spinner } ;
55use colored:: * ;
66use indicatif:: HumanBytes ;
77use std:: path:: { Path , PathBuf } ;
@@ -21,7 +21,7 @@ impl<'a> Downloader<'a> {
2121 }
2222 }
2323
24- pub fn download ( & self ) -> anyhow:: Result < PathBuf > {
24+ pub fn download ( & self , spnr : & Spinner ) -> anyhow:: Result < PathBuf > {
2525 let v = & self . release . version ;
2626 let v_str = v. to_string ( ) ;
2727
@@ -32,7 +32,13 @@ impl<'a> Downloader<'a> {
3232 }
3333
3434 let dist = url:: release ( & self . config . dist_mirror , & v) ;
35+
36+ spnr. update_msg ( "Checking version..." . to_string ( ) ) ;
37+
3538 let res = ureq:: get ( & dist. url ) . call ( ) ?;
39+
40+ spnr. stop ( ) ;
41+
3642 let len = res
3743 . header ( "Content-Length" )
3844 . and_then ( |x| x. parse :: < u64 > ( ) . ok ( ) ) ;
Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ impl Spinner {
9090 self . spinner . finish_and_clear ( ) ;
9191 }
9292
93- // pub fn update_msg(&self, msg: String) {
94- // self.spinner.set_message(msg);
95- // }
93+ pub fn update_msg ( & self , msg : String ) {
94+ self . spinner . set_message ( msg) ;
95+ }
9696}
You can’t perform that action at this time.
0 commit comments