You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`create-rust-github-repo` is a CLI program that creates a new repository on GitHub, clones it locally, initializes a Rust project, copies the configs from a pre-existing directory.
Target directory for cloning the repository (must include the repo name) (defaults to "{current_dir}/{repo_name}") (see also: --workspace)
55
57
-w, --workspace <WORKSPACE>
56
58
Parent of the target directory for cloning the repository (must NOT include the repo name). If this option is specified, then the repo is cloned to "{workspace}/{repo_name}". The --dir option overrides this option
59
+
--shell <SHELL>
60
+
Shell to use for executing commands [default: /bin/sh]
Copy file name to clipboardExpand all lines: src/lib.rs
+98-27Lines changed: 98 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
use std::collections::HashMap;
1
2
use std::env::current_dir;
2
3
use std::ffi::OsStr;
3
4
use std::io;
@@ -27,6 +28,7 @@ impl RepoVisibility {
27
28
}
28
29
29
30
#[derive(Parser,Setters,Debug)]
31
+
#[command(version, about, author, after_help = "All command arg options support the following substitutions:\n* {{name}} - substituted with --name arg\n")]
30
32
#[setters(into)]
31
33
pubstructCreateRustGithubRepo{
32
34
#[arg(long, short = 'n', help = "Repository name")]
#[arg(long, short, help = "Parent of the target directory for cloning the repository (must NOT include the repo name). If this option is specified, then the repo is cloned to \"{workspace}/{repo_name}\". The --dir option overrides this option", value_parser = value_parser!(PathBuf))]
39
41
workspace:Option<PathBuf>,
40
42
43
+
#[arg(long, help = "Shell to use for executing commands", default_value = "/bin/sh")]
44
+
shell:String,
45
+
41
46
#[arg(long, short = 'v', help = "Repository visibility", value_enum, default_value_t)]
exec("gh",["repo","clone",&self.name, dir.to_str().unwrap()],self.gh_repo_clone_args.into_iter(),¤t_dir).context("Failed to clone repository")?;
96
-
97
-
// Run cargo init
98
-
exec("cargo",["init"],self.cargo_init_args.into_iter(),&dir).context("Failed to initialize Cargo project")?;
88
+
let substitutions = HashMap::<&'staticstr,&str>::from([("{{name}}",self.name.as_str())]);
89
+
90
+
let repo_exists = success(&self.shell,["-c"],[self.repo_exists_cmd],¤t_dir,&substitutions)?;
91
+
92
+
if !repo_exists {
93
+
// Create a GitHub repo
94
+
exec(
95
+
"gh",
96
+
[
97
+
"repo",
98
+
"create",
99
+
&self.name,
100
+
self.visibility.to_gh_create_repo_flag(),
101
+
],
102
+
self.gh_repo_create_args,
103
+
¤t_dir,
104
+
&substitutions,
105
+
)
106
+
.context("Failed to create GitHub repository")?;
107
+
}
108
+
109
+
if !dir.exists(){
110
+
// Clone the repo
111
+
exec("gh",["repo","clone",&self.name, dir.to_str().unwrap()],self.gh_repo_clone_args.into_iter(),¤t_dir,&substitutions).context("Failed to clone repository")?;
.and_then(|status| if status.success(){Ok(status)}else{Err(io::Error::new(io::ErrorKind::Other,format!("Process exited with with status {}", status)))})
0 commit comments