-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.rs
102 lines (84 loc) · 2.58 KB
/
cli.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::path::PathBuf;
use clap::{ArgGroup, Parser, ValueEnum, ValueHint};
use serde::Deserialize;
#[derive(ValueEnum, Deserialize, Clone)]
#[serde(remote = "tcd::gql::prelude::Format")]
pub enum Format {
Json,
Csv,
}
impl From<Format> for tcd::gql::prelude::Format {
fn from(format: Format) -> Self {
match format {
Format::Json => tcd::gql::prelude::Format::Json,
Format::Csv => tcd::gql::prelude::Format::Csv,
}
}
}
impl From<&Format> for tcd::gql::prelude::Format {
fn from(format: &Format) -> Self {
match format {
Format::Json => tcd::gql::prelude::Format::Json,
Format::Csv => tcd::gql::prelude::Format::Csv,
}
}
}
impl std::fmt::Display for Format {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Format::Json => write!(f, "json"),
Format::Csv => write!(f, "csv"),
}
}
}
#[derive(Parser)]
#[clap(
author,
version,
about,
help_template = "
{author-with-newline}{about-with-newline}
{usage-heading} {usage}
{all-args}{after-help}
"
)]
#[clap(group(ArgGroup::new("out").required(false).args(&["output", "postgres", "stdout"])))]
#[clap(group(ArgGroup::new("in").required(true).args(&["channel", "video"])))]
pub struct Args {
/// The channel(s) to download
#[clap(short = 'c', long)]
pub channel: Vec<String>,
/// The Twitch client ID to use in the request headers
#[clap(alias = "id", short = 'i', long)]
pub client_id: Option<String>,
/// Used with --output or --stdout
#[clap(alias = "fmt", short = 'f', long, default_value_t = Format::Csv)]
pub format: Format,
/// Downloads the first n videos from each channel
#[clap(short = 'l', long)]
pub limit: Option<usize>,
/// If specified, polls for new videos every `poll` seconds
#[clap(short = 'e', long, default_value_t = false)]
pub live: bool,
/// If specified, pipes data to the file
#[clap(alias = "out", short = 'o', long, value_hint = ValueHint::FilePath)]
pub output: Option<PathBuf>,
/// The PostgreSQL connection string [default: DATABASE_URL env]
#[clap(alias = "pg", short = 'p', long)]
pub postgres: Option<Option<String>>,
/// Whether to print download progress
#[clap(short = 'q', long, default_value_t = false)]
pub quiet: bool,
/// If specified, pipes data to stdout
#[clap(short = 's', long)]
pub stdout: bool,
/// The number of threads to use
#[clap(short = 't', long, default_value_t = 10)]
pub threads: usize,
/// The video ids to download the chat for
#[clap(short = 'v', long)]
pub video: Vec<i64>,
/// The number of minutes to wait between polls (`live` only)
#[clap(short = 'w', long, default_value_t = 30.)]
pub wait: f64,
}