Skip to content

Commit 9dff3ce

Browse files
committed
fix: resolve test failure from arg_required_else_help and clippy warnings
- Move "show help on no subcommand" logic from clap attribute to main() to avoid Cli::parse() calling exit() during tests - Fix 27 uninlined_format_args clippy warnings across the codebase
1 parent 0910550 commit 9dff3ce

11 files changed

Lines changed: 34 additions & 33 deletions

File tree

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You can also browse the available templates at the GitHub &
1919
TopTal collections using the `search` command.";
2020

2121
#[derive(Parser, Debug)]
22-
#[command(author, version, about, long_about = LONG_ABOUT, arg_required_else_help = true)]
22+
#[command(author, version, about, long_about = LONG_ABOUT)]
2323
pub struct Cli {
2424
/// Refresh the cache (templates are cached for 1h)
2525
#[arg(short = 'r', long = "refresh", global = true)]

src/commands/create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub fn command(cmd: &CommandCreate) -> Result<()> {
7272
}
7373

7474
// Print template to stdout
75-
println!("{}", output);
75+
println!("{output}");
7676

7777
Ok(())
7878
}

src/commands/search/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn handle_mouse_events(event: MouseEvent, app: &mut UIState) -> Result<()> {
209209
MouseEventKind::ScrollDown => {
210210
if now.duration_since(app.last_scroll_time) > Duration::from_millis(15) {
211211
app.list_next(if is_shift || is_alt {
212-
println!("Scrolling {} {}", is_shift, is_alt);
212+
println!("Scrolling {is_shift} {is_alt}");
213213
Some(10)
214214
} else {
215215
Some(1)

src/commands/search/views/home/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use ratatui::{text, Frame};
1010
fn create_tabs<'a>(tab_titles: Vec<String>, list_tab: usize) -> anyhow::Result<Tabs<'a>> {
1111
let items = tab_titles
1212
.into_iter()
13-
.map(|t| Line::from(format!(" {} ", t)))
13+
.map(|t| Line::from(format!(" {t} ")))
1414
.collect::<Vec<Line>>();
1515
let block = Block::default()
1616
.borders(Borders::ALL)

src/commands/search/views/home/main_side.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn create_selected<'a>(
3636
.map(|s| {
3737
let name = s.template.value.name().unwrap();
3838
let prefix = s.kind.name();
39-
ListItem::new(format!("{} - {}", prefix, name))
39+
ListItem::new(format!("{prefix} - {name}"))
4040
})
4141
.collect();
4242

src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::cli::{get_cli, Commands};
1010
use crate::commands::completions;
1111
use crate::commands::create;
1212
use crate::commands::search;
13-
use anyhow::{anyhow, Result};
13+
use anyhow::Result;
1414
use indoc::eprintdoc;
1515
use yansi::Paint;
1616

@@ -22,7 +22,11 @@ fn main() -> Result<()> {
2222
Some(Commands::Create(cmd)) => create::command(cmd),
2323
Some(Commands::Search) => search::command(),
2424
Some(Commands::Completions { shell }) => completions::command(shell),
25-
None => Err(anyhow!("No command specified")),
25+
None => {
26+
use clap::CommandFactory;
27+
crate::cli::Cli::command().print_help()?;
28+
Ok(())
29+
}
2630
};
2731

2832
// Handle error output and program termination

src/template/collection/github.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ impl GithubTemplates {
8181

8282
// Root template
8383
if !path.contains('/') {
84-
let template = Template::new(&format!("gh:{}", path))?;
84+
let template = Template::new(&format!("gh:{path}"))?;
8585
root.push(template);
8686
}
8787
// Global template
8888
else if let Some(path) = path.strip_prefix("Global/") {
89-
let template = Template::new(&format!("ghg:{}", path))?;
89+
let template = Template::new(&format!("ghg:{path}"))?;
9090
global.push(template);
9191
}
9292
// Community template
9393
else if let Some(path) = path.strip_prefix("community/") {
94-
let template = Template::new(&format!("ghc:{}", path))?;
94+
let template = Template::new(&format!("ghc:{path}"))?;
9595
community.push(template);
9696
}
9797
}
@@ -165,24 +165,23 @@ pub struct TreeItem {
165165
/// Get the GitHub tree for a repository
166166
pub fn gh_tree(owner: &str, repo: &str, branch: &str, recursive: bool) -> Result<Tree> {
167167
let mut url = format!(
168-
"{}/repos/{owner}/{repo}/git/trees/{branch}",
169-
GITHUB_API_ENDPOINT
168+
"{GITHUB_API_ENDPOINT}/repos/{owner}/{repo}/git/trees/{branch}"
170169
);
171170

172171
if recursive {
173-
url = format!("{}?recursive=true", url)
172+
url = format!("{url}?recursive=true")
174173
}
175174

176175
let res = http()
177176
.get(&url)
178177
.set("Accept", GITHUB_API_ACCEPT)
179178
.call()
180-
.with_context(|| format!("GitHub API error when fetching repo tree\n\n{}", url))?
179+
.with_context(|| format!("GitHub API error when fetching repo tree\n\n{url}"))?
181180
.into_string()
182-
.with_context(|| format!("Failed to parse GitHub API response to string\n\n{}", url))?;
181+
.with_context(|| format!("Failed to parse GitHub API response to string\n\n{url}"))?;
183182

184183
let parsed = serde_json::from_str(&res)
185-
.with_context(|| format!("Failed to parse GitHub API response to JSON\n\n{}", url))?;
184+
.with_context(|| format!("Failed to parse GitHub API response to JSON\n\n{url}"))?;
186185

187186
Ok(parsed)
188187
}

src/template/collection/toptal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl TopTalTemplates {
5050

5151
/// Fetch the templates from the TopTal API
5252
fn fetch() -> Result<Self> {
53-
let url = format!("{}/list?format=lines", TOPTAL_API);
53+
let url = format!("{TOPTAL_API}/list?format=lines");
5454

5555
let list = http()
5656
.get(&url)
@@ -61,7 +61,7 @@ impl TopTalTemplates {
6161

6262
let templates = list
6363
.lines()
64-
.map(|s| Template::new(&format!("tt:{}", s)))
64+
.map(|s| Template::new(&format!("tt:{s}")))
6565
.collect::<Result<Vec<Template>>>()?;
6666

6767
let updated = SystemTime::now();

src/template/item/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl TemplateValue {
128128
Self::Url(_) => {
129129
let url = self.name()?;
130130
let url = Url::parse(&url)
131-
.with_context(|| format!("[Ignore Template] Invalid URL: {}", url))?;
131+
.with_context(|| format!("[Ignore Template] Invalid URL: {url}"))?;
132132
Ok(url.to_string())
133133
}
134134
Self::File(_) => {
@@ -143,33 +143,31 @@ impl TemplateValue {
143143
}
144144
Self::GitHubRepo(_) => {
145145
let repo = self.name()?;
146-
let url = format!("{}/{}", GITHUB_RAW, repo);
146+
let url = format!("{GITHUB_RAW}/{repo}");
147147
Ok(url)
148148
}
149149
Self::GitHubGlobal(_) => {
150150
let repo = self.name()?;
151151
let url = format!(
152-
"{}/github/gitignore/main/Global/{}.gitignore",
153-
GITHUB_RAW, repo
152+
"{GITHUB_RAW}/github/gitignore/main/Global/{repo}.gitignore"
154153
);
155154
Ok(url)
156155
}
157156
Self::GitHubCommunity(_) => {
158157
let repo = self.name()?;
159158
let url = format!(
160-
"{}/github/gitignore/main/community/{}.gitignore",
161-
GITHUB_RAW, repo
159+
"{GITHUB_RAW}/github/gitignore/main/community/{repo}.gitignore"
162160
);
163161
Ok(url)
164162
}
165163
Self::GitHub(_) => {
166164
let repo = self.name()?;
167-
let url = format!("{}/github/gitignore/main/{}.gitignore", GITHUB_RAW, repo);
165+
let url = format!("{GITHUB_RAW}/github/gitignore/main/{repo}.gitignore");
168166
Ok(url)
169167
}
170168
Self::TopTal(_) => {
171169
let name = self.name()?;
172-
let url = format!("{}/{}", TOPTAL_API, name);
170+
let url = format!("{TOPTAL_API}/{name}");
173171
Ok(url)
174172
}
175173
}
@@ -217,7 +215,7 @@ impl Template {
217215
TemplateValue::File(_) => {
218216
let path = self.value.url()?;
219217
let content = fs::read_to_string(&path).with_context(|| {
220-
format!("Failed to read ignore file template at path\n{}", path)
218+
format!("Failed to read ignore file template at path\n{path}")
221219
})?;
222220
Ok(content)
223221
}
@@ -229,11 +227,11 @@ impl Template {
229227
let content: String = http().get(&url)
230228
.call()
231229
.with_context(|| {
232-
format!("Failed to fetch ignore template at URL. The template might not exist...\n{}", url)
230+
format!("Failed to fetch ignore template at URL. The template might not exist...\n{url}")
233231
})?
234232
.into_string()
235233
.with_context(|| {
236-
format!("Failed to parse response when fetching ignore template at URL\n{}", url)
234+
format!("Failed to parse response when fetching ignore template at URL\n{url}")
237235
})?;
238236
let content = content.trim();
239237
TemplateCache::set(&url, content)?;

src/template/list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ impl TemplateList {
7575

7676
let cmds = cmds.join(" ");
7777

78-
Ok(format!("gitnr create {}", cmds).trim().to_string())
78+
Ok(format!("gitnr create {cmds}").trim().to_string())
7979
}
8080
}

0 commit comments

Comments
 (0)