Skip to content

Commit

Permalink
default output path to the RFC 140 format if pkgs/by-name exists
Browse files Browse the repository at this point in the history
NixOS/nixpkgs#237439 has been merged
  • Loading branch information
figsoda committed Sep 8, 2023
1 parent a606564 commit 8895fcf
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
fmt::Write as _,
fs::{create_dir_all, metadata, read_dir, read_to_string, File},
io::{stderr, BufRead, BufReader, Write as _},
path::PathBuf,
path::{Path, PathBuf},
};

use anyhow::{Context, Result};
Expand Down Expand Up @@ -416,18 +416,33 @@ async fn run() -> Result<()> {
.and_then(|i: usize| choices.get(i))
.unwrap_or_else(|| &choices[0]);

let output = match opts.output {
Some(output) => output,
None => {
editor.set_helper(Some(Prompter::Path(FilenameCompleter::new())));
let output =
editor.readline(&prompt("Enter output path (defaults to current directory)"))?;
editor.set_helper(None);
if output.is_empty() {
PathBuf::from(".")
} else {
PathBuf::from(output)
}
let output = if let Some(output) = opts.output {
output
} else {
editor.set_helper(Some(Prompter::Path(FilenameCompleter::new())));

let attr = if pname.starts_with(|c| matches!(c, 'A'..='Z' | 'a'..='z' | '_')) {
pname.clone()
} else {
format!("_{pname}")
};

let msg = &prompt("Enter output path (leave as empty for the current directory)");
let output = if Path::new("pkgs/by-name").is_dir() {
let path = &format!(
"pkgs/by-name/{}/{attr}/package.nix",
attr.chars().take(2).collect::<String>(),
);
editor.readline_with_initial(msg, (path, ""))
} else {
editor.readline(msg)
}?;
editor.set_helper(None);

if output.is_empty() {
PathBuf::from(".")
} else {
PathBuf::from(output)
}
};

Expand Down

0 comments on commit 8895fcf

Please sign in to comment.