Wire in the ListReleases primary command
Hey, look at that. I can do the thing what with the stuff and such.
This commit is contained in:
15
src/cli.rs
15
src/cli.rs
@@ -1,23 +1,20 @@
|
|||||||
use clap::{
|
use clap::{Parser, Subcommand};
|
||||||
Parser,
|
|
||||||
Subcommand
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[arg(short = 'o', long = "owner")]
|
#[arg(short = 'o', long = "owner")]
|
||||||
repo_owner: Option<String>,
|
pub repo_owner: Option<String>,
|
||||||
#[arg(short = 'n', long = "repo_name")]
|
#[arg(short = 'n', long = "repo_name")]
|
||||||
repo_name: Option<String>,
|
pub repo_name: Option<String>,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Option<Commands>
|
pub command: Commands,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand, Debug)]
|
#[derive(Subcommand, Debug)]
|
||||||
enum Commands {
|
pub enum Commands {
|
||||||
ListReleases{
|
ListReleases {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
list: bool,
|
list: bool,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use serde::Deserialize;
|
|||||||
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
|
|
||||||
pub fn module_echo(){
|
pub fn module_echo() {
|
||||||
println!("hello from lib.rs!");
|
println!("hello from lib.rs!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ pub struct ReleaseInfo {
|
|||||||
prerelease: bool,
|
prerelease: bool,
|
||||||
created_at: String,
|
created_at: String,
|
||||||
published_at: String,
|
published_at: String,
|
||||||
author: Author
|
author: Author,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@@ -33,5 +33,5 @@ pub struct Author {
|
|||||||
login_name: String,
|
login_name: String,
|
||||||
source_id: usize,
|
source_id: usize,
|
||||||
full_name: String,
|
full_name: String,
|
||||||
email: String
|
email: String,
|
||||||
}
|
}
|
||||||
|
|||||||
45
src/main.rs
45
src/main.rs
@@ -1,36 +1,33 @@
|
|||||||
use gt_tools::{
|
use gt_tools::{ReleaseInfo, cli::Args};
|
||||||
ReleaseInfo,
|
|
||||||
cli::Args
|
|
||||||
};
|
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use reqwest::Error;
|
use reqwest::Error;
|
||||||
use reqwest::header::{
|
use reqwest::header::{ACCEPT, USER_AGENT};
|
||||||
USER_AGENT,
|
|
||||||
ACCEPT
|
|
||||||
};
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Error> {
|
async fn main() -> Result<(), Error> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
println!("{:?}", args);
|
match args.command {
|
||||||
|
gt_tools::cli::Commands::ListReleases { list } => {
|
||||||
let request_url = format!(
|
let request_url = format!(
|
||||||
"http:/localhost:3000/api/v1/repos/{owner}/{repo}/releases",
|
"http:/localhost:3000/api/v1/repos/{owner}/{repo}/releases",
|
||||||
owner = "robert",
|
owner = "robert",
|
||||||
repo = "rcalc",
|
repo = "rcalc",
|
||||||
);
|
);
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let response = client
|
let response = client
|
||||||
.get(request_url)
|
.get(request_url)
|
||||||
.header(USER_AGENT, "gt-tools-test-agent")
|
.header(USER_AGENT, "gt-tools-test-agent")
|
||||||
.header(ACCEPT, "application/json")
|
.header(ACCEPT, "application/json")
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
let body_text: Vec<ReleaseInfo> = response.json().await?;
|
let body_text: Vec<ReleaseInfo> = response.json().await?;
|
||||||
|
|
||||||
|
println!("{:?}", body_text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
println!("{:?}", body_text);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user