Skip to content
This repository was archived by the owner on Aug 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["0xazure <stuart.crust@gmail.com>"]

[dependencies]
clap = "~2.32.0"
reqwest = "0.8.7"
serde = "1.0"
serde_json = "1.0"
Expand Down
25 changes: 11 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
extern crate chrono;
extern crate clap;
extern crate reqwest;
extern crate serde_derive;
extern crate serde_json;

use chrono::{DateTime, Utc};
use reqwest::header::{qitem, Accept, Authorization, Bearer, Link, RelationType, UserAgent};
use serde_derive::Deserialize;
use std::{env, error, fmt, mem};
use std::{error, fmt, mem};

#[derive(Debug)]
pub struct Config {
Expand All @@ -15,19 +16,6 @@ pub struct Config {
}

impl Config {
pub fn new(mut args: env::Args) -> Result<Config, &'static str> {
args.next();

let username = match args.next() {
None => return Err("No username provided"),
Some(arg) => arg,
};

let token = args.next();

Ok(Config { username, token })
}

fn url(self) -> Option<String> {
Some(format!(
"https://api.github.com/users/{}/starred",
Expand All @@ -36,6 +24,15 @@ impl Config {
}
}

impl<'a> From<clap::ArgMatches<'a>> for Config {
fn from(matches: clap::ArgMatches) -> Self {
Config {
username: matches.value_of("USERNAME").unwrap().to_owned(),
token: matches.value_of("TOKEN").map(String::from),
}
}
}

#[derive(Debug)]
struct ClientBuilder {
inner: reqwest::ClientBuilder,
Expand Down
22 changes: 17 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
extern crate clap;
extern crate supernova;

use std::{env, process};
use clap::{App, Arg, crate_name, crate_version};
use std::process;
use supernova::Config;

fn main() {
let config = Config::new(env::args()).unwrap_or_else(|err| {
println!("Problem parsing arguments: {}", err);
process::exit(1);
});
let config: Config = App::new(crate_name!())
.version(crate_version!())
.arg(
Arg::with_name("USERNAME")
.help("The user whose stars to collect")
.required(true),
).arg(
Arg::with_name("TOKEN")
.short("t")
.long("token")
.help("Sets the authentication token for requests to GitHub")
.takes_value(true),
).get_matches()
.into();

if let Err(e) = supernova::collect_stars(config) {
println!("Application error: {}", e);
Expand Down