Skip to content

Commit 8b2a790

Browse files
authored
Merge pull request #463 from gramlang/codex/pathbuf-cli-paths
Use PathBuf for CLI path arguments
2 parents 7ac4f2a + a723c84 commit 8b2a790

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/main.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ use crate::{
2222
};
2323
use clap::{ArgAction, Args, CommandFactory, Parser, Subcommand as ClapSubcommand};
2424
use clap_complete::{Shell, generate};
25-
use std::{fs::read_to_string, io::stdout, path::Path, process::exit, thread};
25+
use std::{
26+
fs::read_to_string,
27+
io::stdout,
28+
path::{Path, PathBuf},
29+
process::exit,
30+
thread,
31+
};
2632

2733
// The name of the program binary
2834
const BIN_NAME: &str = "gram";
@@ -50,7 +56,7 @@ struct Cli {
5056
_version: Option<bool>,
5157

5258
#[arg(help = "Set the path to the program entrypoint")]
53-
path: Option<String>,
59+
path: Option<PathBuf>,
5460

5561
#[command(subcommand)]
5662
command: Option<GramCommand>,
@@ -59,7 +65,7 @@ struct Cli {
5965
#[derive(Args)]
6066
struct ProgramPathArg {
6167
#[arg(help = "Set the path to the program entrypoint")]
62-
path: String,
68+
path: PathBuf,
6369
}
6470

6571
#[derive(Args)]
@@ -202,18 +208,18 @@ fn entry() -> Result<(), Error> {
202208
// Check if the user provided a path as the first argument.
203209
if let Some(source_path) = cli.path.as_deref() {
204210
// We got a path. Run the program at that path.
205-
run(Path::new(source_path), false)?;
211+
run(source_path, false)?;
206212
} else {
207213
// Decide what to do based on the subcommand.
208214
match cli.command {
209215
Some(GramCommand::Check(args)) => {
210216
// Check the program.
211-
run(Path::new(&args.path), true)?;
217+
run(&args.path, true)?;
212218
}
213219

214220
Some(GramCommand::Run(args)) => {
215221
// Run the program.
216-
run(Path::new(&args.path), false)?;
222+
run(&args.path, false)?;
217223
}
218224

219225
Some(GramCommand::ShellCompletion(args)) => {

0 commit comments

Comments
 (0)