Skip to content

Commit f9ffcef

Browse files
committed
Add some default values to interactive init
1 parent c232a67 commit f9ffcef

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/commands/init.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
use anyhow::{anyhow, Result};
22
use 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

55
use 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+
1016
pub 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

3336
pub 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 {

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async fn main() -> Result<()> {
120120
if no_interactive {
121121
commands::init(
122122
&client,
123-
path.unwrap_or_else(|| current_dir().expect("Failed to fetch current dir")),
123+
&path.unwrap_or_else(|| current_dir().expect("Failed to fetch current dir")),
124124
version,
125125
game_version,
126126
name,

0 commit comments

Comments
 (0)