Skip to content

Instantly share code, notes, and snippets.

@Wafelack
Created August 10, 2020 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wafelack/80beb27e265fee245252fd948606b2a7 to your computer and use it in GitHub Desktop.
Save Wafelack/80beb27e265fee245252fd948606b2a7 to your computer and use it in GitHub Desktop.
github_cloner
use std::process::Command;
// Declaring public function clone_from_github
pub fn clone_from_github(repo: &str) /* Taking one paramater (a string slice) */ {
let mut full_link = String::from("https://github.com/"); //Declaring a new variable of type String that is mutable
full_link.push_str(repo); // Adding repo name at the end of the string
Command::new("git") //running git command
.arg("clone") // with argument clone
.arg(full_link) // with final argument is repo link
.spawn() // Running command
.expect("Failed to clone repo"); // Set message displayed in case of command failure
}
use std::env;
// Using environment library
mod cloner; // Using my cloner.rs file
use cloner::clone_from_github; // Using function from my cloner module
fn main() {
// Using command line arguments
let argv: Vec<String> = env::args().collect();
let argc = argv.len();
// Verifying number of args
if argc < 2 {
println!("Usage: club <username>/<reponame>");
return;
}
// Running clone_from_github function
clone_from_github(&argv[1]);
println!("Cloning from GitHub ...");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment