@@ -37,8 +37,7 @@ use libium::config::{
37
37
structs:: { Config , ModIdentifier , Modpack , Profile } ,
38
38
} ;
39
39
use octocrab:: OctocrabBuilder ;
40
- use once_cell:: sync:: { Lazy , OnceCell } ;
41
- use reqwest:: header:: { AUTHORIZATION , USER_AGENT } ;
40
+ use once_cell:: sync:: Lazy ;
42
41
use std:: {
43
42
env:: { var, var_os} ,
44
43
process:: ExitCode ,
@@ -49,7 +48,6 @@ const CROSS: &str = "×";
49
48
pub static TICK : Lazy < ColoredString > = Lazy :: new ( || "✓" . green ( ) ) ;
50
49
pub static YELLOW_TICK : Lazy < ColoredString > = Lazy :: new ( || "✓" . yellow ( ) ) ;
51
50
pub static THEME : Lazy < ColorfulTheme > = Lazy :: new ( Default :: default) ;
52
- pub static GITHUB_TOKEN : OnceCell < String > = OnceCell :: new ( ) ;
53
51
#[ allow( clippy:: expect_used) ]
54
52
pub static STYLE_NO : Lazy < ProgressStyle > = Lazy :: new ( || {
55
53
ProgressStyle :: default_bar ( )
@@ -84,6 +82,18 @@ fn main() -> ExitCode {
84
82
let runtime = builder. build ( ) . expect ( "Could not initialise Tokio runtime" ) ;
85
83
if let Err ( err) = runtime. block_on ( actual_main ( cli) ) {
86
84
eprintln ! ( "{}" , err. to_string( ) . red( ) . bold( ) ) ;
85
+ if err
86
+ . to_string ( )
87
+ . to_lowercase ( )
88
+ . contains ( "error trying to connect" )
89
+ {
90
+ eprintln ! (
91
+ "{}" ,
92
+ "Verify that you are connnected to the internet"
93
+ . yellow( )
94
+ . bold( )
95
+ ) ;
96
+ }
87
97
ExitCode :: FAILURE
88
98
} else {
89
99
ExitCode :: SUCCESS
@@ -115,15 +125,11 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
115
125
} ;
116
126
}
117
127
128
+ let mut github = OctocrabBuilder :: new ( ) ;
118
129
if let Some ( token) = cli_app. github_token {
119
- GITHUB_TOKEN . get_or_init ( || token . to_string ( ) ) ;
130
+ github = github . personal_token ( token ) ;
120
131
} else if let Ok ( token) = var ( "GITHUB_TOKEN" ) {
121
- GITHUB_TOKEN . get_or_init ( || token. to_string ( ) ) ;
122
- }
123
-
124
- let mut github = OctocrabBuilder :: new ( ) ;
125
- if let Some ( token) = GITHUB_TOKEN . get ( ) {
126
- github = github. personal_token ( token. clone ( ) ) ;
132
+ github = github. personal_token ( token) ;
127
133
}
128
134
129
135
let modrinth = Ferinth :: new (
@@ -160,7 +166,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
160
166
ignore_mod_loader,
161
167
} => {
162
168
let profile = get_active_profile ( & mut config) ?;
163
- check_internet ( ) . await ?;
164
169
eprint ! ( "Adding mod... " ) ;
165
170
if let Ok ( project_id) = identifier. parse :: < i32 > ( ) {
166
171
let name = libium:: add:: curseforge (
@@ -225,7 +230,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
225
230
let profile = get_active_profile ( & mut config) ?;
226
231
check_empty_profile ( profile) ?;
227
232
if verbose {
228
- check_internet ( ) . await ?;
229
233
subcommands:: list:: verbose ( modrinth, curseforge, profile, markdown) . await ?;
230
234
} else {
231
235
println ! (
@@ -267,7 +271,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
267
271
output_dir,
268
272
install_overrides,
269
273
} => {
270
- check_internet ( ) . await ?;
271
274
if let Ok ( project_id) = identifier. parse :: < i32 > ( ) {
272
275
subcommands:: modpack:: add:: curseforge (
273
276
& curseforge,
@@ -323,7 +326,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
323
326
subcommands:: modpack:: switch ( & mut config, modpack_name) ?;
324
327
}
325
328
ModpackSubCommands :: Upgrade => {
326
- check_internet ( ) . await ?;
327
329
subcommands:: modpack:: upgrade (
328
330
& modrinth,
329
331
& curseforge,
@@ -353,7 +355,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
353
355
name,
354
356
output_dir,
355
357
} => {
356
- check_internet ( ) . await ?;
357
358
subcommands:: profile:: configure (
358
359
get_active_profile ( & mut config) ?,
359
360
game_version,
@@ -370,9 +371,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
370
371
name,
371
372
output_dir,
372
373
} => {
373
- if game_version. is_none ( ) {
374
- check_internet ( ) . await ?;
375
- }
376
374
subcommands:: profile:: create (
377
375
& mut config,
378
376
import,
@@ -417,7 +415,6 @@ async fn actual_main(mut cli_app: Ferium) -> Result<()> {
417
415
subcommands:: remove ( profile, mod_names) ?;
418
416
}
419
417
SubCommands :: Upgrade => {
420
- check_internet ( ) . await ?;
421
418
let profile = get_active_profile ( & mut config) ?;
422
419
check_empty_profile ( profile) ?;
423
420
subcommands:: upgrade ( modrinth, curseforge, github. build ( ) ?, profile) . await ?;
@@ -482,31 +479,3 @@ fn check_empty_profile(profile: &Profile) -> Result<()> {
482
479
}
483
480
Ok ( ( ) )
484
481
}
485
-
486
- /// Check for an internet connection
487
- async fn check_internet ( ) -> Result < ( ) > {
488
- let client = reqwest:: Client :: default ( ) ;
489
-
490
- client
491
- . get ( ferinth:: BASE_URL . as_ref ( ) )
492
- . send ( )
493
- . await ?
494
- . error_for_status ( ) ?;
495
-
496
- client
497
- . get ( "https://api.curseforge.com/" )
498
- . send ( )
499
- . await ?
500
- . error_for_status ( ) ?;
501
-
502
- let mut github = client. get ( "https://api.github.com/" ) . header (
503
- USER_AGENT ,
504
- concat ! ( env!( "CARGO_PKG_NAME" ) , " " , env!( "CARGO_PKG_VERSION" ) ) ,
505
- ) ;
506
- if let Some ( token) = GITHUB_TOKEN . get ( ) {
507
- github = github. header ( AUTHORIZATION , format ! ( "Bearer {token}" ) ) ;
508
- }
509
- github. send ( ) . await ?. error_for_status ( ) ?;
510
-
511
- Ok ( ( ) )
512
- }
0 commit comments