11use anyhow:: { anyhow, Result } ;
22use inquire:: { Select , Text } ;
3- use std:: { collections:: HashMap , env:: current_dir, fs, path:: PathBuf } ;
3+ use std:: { collections:: HashMap , env:: current_dir, fs, path:: Path } ;
44
55use crate :: {
66 manifest:: { self , Manifest } ,
77 modrinth:: { Client , VersionType } ,
88} ;
99
10+ fn name_from_path ( path : & Path ) -> & str {
11+ path. file_name ( )
12+ . and_then ( |name| name. to_str ( ) )
13+ . unwrap_or ( "pack" )
14+ }
15+
1016pub async fn init_interactive ( client : & Client ) -> Result < ( ) > {
11- let name = Text :: new ( "Name" ) . prompt ( ) ?;
12- let version = Text :: new ( "Version" ) . prompt ( ) ?;
17+ let pwd = current_dir ( ) . expect ( "Failed to fetch current dir" ) ;
18+
19+ let name = Text :: new ( "Name" )
20+ . with_default ( name_from_path ( & pwd) )
21+ . prompt ( ) ?;
22+ let version = Text :: new ( "Version" ) . with_default ( "0.1.0" ) . prompt ( ) ?;
1323
1424 let versions = client
1525 . get_game_versions ( )
@@ -20,31 +30,20 @@ pub async fn init_interactive(client: &Client) -> Result<()> {
2030
2131 let game_version = Select :: new ( "Game version" , versions) . prompt ( ) ?;
2232
23- init (
24- client,
25- current_dir ( ) . expect ( "Failed to fetch current dir" ) ,
26- version,
27- Some ( game_version) ,
28- Some ( name) ,
29- )
30- . await
33+ init ( client, & pwd, version, Some ( game_version) , Some ( name) ) . await
3134}
3235
3336pub async fn init (
3437 client : & Client ,
35- path : PathBuf ,
38+ path : & Path ,
3639 version : String ,
3740 game_version : Option < String > ,
3841 name : Option < String > ,
3942) -> Result < ( ) > {
4043 let name = if let Some ( name) = name {
4144 name
4245 } else {
43- // TODO: some degree of error handling I guess
44- path. file_name ( )
45- . and_then ( |name| name. to_str ( ) )
46- . unwrap_or ( "pack" )
47- . to_string ( )
46+ name_from_path ( path) . to_string ( )
4847 } ;
4948
5049 let minecraft_version = if let Some ( game_version) = game_version {
0 commit comments