Use current-dir as final fallback repo name
It all falls into place! I had been dreading doing this bit, but after updating the usage guide I realized the CLI args should be split, too. Which finally means that I can just glue on the PWD name as a final fallback for the repo name. Try the args, then the config file(s), then PWD. If nothing works, the user is in a world of hurt. Bail out.
This commit is contained in:
@@ -23,6 +23,8 @@ pub enum Error {
|
|||||||
Placeholder, // TODO: Enumerate error modes
|
Placeholder, // TODO: Enumerate error modes
|
||||||
MissingGiteaUrl, // the gitea URL wasn't specified on the CLI, env, or config file.
|
MissingGiteaUrl, // the gitea URL wasn't specified on the CLI, env, or config file.
|
||||||
MissingRepoFRQN, // either the owner, repo, or both weren't specified in the loaded PartialConfig
|
MissingRepoFRQN, // either the owner, repo, or both weren't specified in the loaded PartialConfig
|
||||||
|
MissingRepoOwner,
|
||||||
|
MissingRepoName,
|
||||||
WrappedConfigErr(config::Error),
|
WrappedConfigErr(config::Error),
|
||||||
WrappedReqwestErr(reqwest::Error),
|
WrappedReqwestErr(reqwest::Error),
|
||||||
MissingAuthToken,
|
MissingAuthToken,
|
||||||
|
|||||||
35
src/main.rs
35
src/main.rs
@@ -12,8 +12,6 @@ use reqwest::header::ACCEPT;
|
|||||||
async fn main() -> Result<(), gt_tool::Error> {
|
async fn main() -> Result<(), gt_tool::Error> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
// TODO: Heuristics to guess project path
|
|
||||||
// See issue #8: https://git.gelvin.dev/robert/gt-tool/issues/8
|
|
||||||
let project_path =
|
let project_path =
|
||||||
args.project
|
args.project
|
||||||
.map(PathBuf::from)
|
.map(PathBuf::from)
|
||||||
@@ -32,21 +30,17 @@ async fn main() -> Result<(), gt_tool::Error> {
|
|||||||
.gitea_url
|
.gitea_url
|
||||||
.or(config.gitea_url)
|
.or(config.gitea_url)
|
||||||
.ok_or(gt_tool::Error::MissingGiteaUrl)?;
|
.ok_or(gt_tool::Error::MissingGiteaUrl)?;
|
||||||
// Config files split the repo FQRN into "owner" and "repo" (confusing naming, sorry)
|
|
||||||
// These must be merged back together and passed along.
|
let owner = args.owner
|
||||||
let conf_fqrn = config
|
.or(config.owner)
|
||||||
.owner
|
.ok_or(gt_tool::Error::MissingRepoOwner)?;
|
||||||
.ok_or(gt_tool::Error::MissingRepoFRQN)
|
|
||||||
.and_then(|mut own| {
|
let repo = args.repo
|
||||||
let repo = config.repo.ok_or(gt_tool::Error::MissingRepoFRQN)?;
|
.or(config.repo)
|
||||||
own.push('/');
|
.or_else(infer_repo)
|
||||||
own.push_str(&repo);
|
.ok_or(gt_tool::Error::MissingRepoName)?;
|
||||||
Ok(own)
|
|
||||||
});
|
let repo_fqrn = String::from(format!("{owner}/{repo}"));
|
||||||
let repo_fqrn = args
|
|
||||||
.repo
|
|
||||||
.ok_or(gt_tool::Error::MissingRepoFRQN)
|
|
||||||
.or(conf_fqrn)?;
|
|
||||||
|
|
||||||
let mut headers = reqwest::header::HeaderMap::new();
|
let mut headers = reqwest::header::HeaderMap::new();
|
||||||
headers.append(ACCEPT, header::HeaderValue::from_static("application/json"));
|
headers.append(ACCEPT, header::HeaderValue::from_static("application/json"));
|
||||||
@@ -176,3 +170,10 @@ fn match_release_by_tag(tag: &String, releases: Vec<Release>) -> Option<Release>
|
|||||||
}
|
}
|
||||||
release
|
release
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn infer_repo() -> Option<String> {
|
||||||
|
let pwd = std::env::current_dir().ok()?;
|
||||||
|
let file_name = pwd.file_name()?;
|
||||||
|
let file_name_string = file_name.to_str()?;
|
||||||
|
Some(String::from(file_name_string))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user