File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ pub mod cache;
3232mod metrics;
3333pub mod profitability;
3434pub mod settings;
35+ pub mod setup;
3536mod sync;
3637pub mod task_completion_processor;
3738pub mod task_context;
@@ -309,6 +310,9 @@ impl Cli {
309310
310311#[ tokio:: main]
311312async fn main ( ) -> anyhow:: Result < ( ) > {
313+ // Create default config if it doesn't exist
314+ setup:: create_config_if_missing ( ) ?;
315+
312316 let cli = Cli :: parse ( ) ;
313317 cli. run ( ) . await
314318}
Original file line number Diff line number Diff line change 1+ use anyhow:: Result ;
2+ use std:: fs;
3+ use std:: path:: PathBuf ;
4+
5+ const DEFAULT_CONFIG : & str = r#"# RPC endpoint URL
6+ rpc_url = "https://api.mainnet-beta.solana.com"
7+
8+ # Path to your Solana keypair file
9+ key_path = "~/.config/solana/id.json"
10+
11+ # Minimum crank fee in lamports
12+ min_crank_fee = 10000
13+ "# ;
14+
15+ pub fn get_default_config_path ( ) -> Option < PathBuf > {
16+ let home_dir = std:: env:: var ( "HOME" )
17+ . or_else ( |_| std:: env:: var ( "USERPROFILE" ) )
18+ . ok ( ) ?;
19+
20+ Some (
21+ PathBuf :: from ( home_dir)
22+ . join ( ".config" )
23+ . join ( "helium" )
24+ . join ( "cli" )
25+ . join ( "tuktuk-crank-turner" )
26+ . join ( "config.toml" ) ,
27+ )
28+ }
29+
30+ fn write_default_config ( config_path : & PathBuf ) -> Result < ( ) > {
31+ if let Some ( parent) = config_path. parent ( ) {
32+ fs:: create_dir_all ( parent) ?;
33+ }
34+
35+ fs:: write ( config_path, DEFAULT_CONFIG ) ?;
36+
37+ Ok ( ( ) )
38+ }
39+
40+ pub fn create_config_if_missing ( ) -> Result < ( ) > {
41+ let Some ( config_path) = get_default_config_path ( ) else {
42+ eprintln ! ( "Warning: Could not determine home directory. Skipping config creation." ) ;
43+ return Ok ( ( ) ) ;
44+ } ;
45+
46+ if !config_path. exists ( ) {
47+ write_default_config ( & config_path) ?;
48+ }
49+
50+ Ok ( ( ) )
51+ }
You can’t perform that action at this time.
0 commit comments