lospec_cli/
cli.rs

1use std::path::PathBuf;
2
3use clap::{Parser, ValueEnum};
4
5use crate::cmd::download::{Format, PngSize};
6
7#[derive(Clone, Debug)]
8pub enum Sorting {
9    Default,
10    AZ,
11    Downloads,
12    Newest,
13}
14
15impl ValueEnum for Sorting {
16    fn value_variants<'a>() -> &'a [Self] {
17        &[Self::Default, Self::AZ, Self::Downloads, Self::Newest]
18    }
19
20    fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
21        Some(match self {
22            Sorting::Default => clap::builder::PossibleValue::new("default"),
23            Sorting::AZ => clap::builder::PossibleValue::new("az"),
24            Sorting::Downloads => clap::builder::PossibleValue::new("downloads"),
25            Sorting::Newest => clap::builder::PossibleValue::new("newest"),
26        })
27    }
28}
29
30impl ToString for Sorting {
31    fn to_string(&self) -> String {
32        match self {
33            Sorting::Default => "default".to_string(),
34            Sorting::AZ => "alphabetical".to_string(),
35            Sorting::Downloads => "downloads".to_string(),
36            Sorting::Newest => "newest".to_string(),
37        }
38    }
39}
40
41#[derive(Debug, Parser)]
42pub enum Cli {
43    #[command(about = "Search for color palettes")]
44    Search {
45        /// Search for palettes with at most N colors
46        #[arg(long, conflicts_with_all = ["min", "exact"])]
47        max: Option<u16>,
48
49        /// Search for palettes with at least N colors
50        #[arg(long, conflicts_with_all = ["max", "exact"])]
51        min: Option<u16>,
52
53        /// Search for palettes with exactly N colors
54        #[arg(long, conflicts_with_all = ["max", "min"])]
55        exact: Option<u16>,
56
57        /// Show page N
58        #[arg(short, long)]
59        page: Option<u16>, // TODO: expand to support multiple pages
60
61        /// Search results sorting
62        #[arg(long, default_value_t = Sorting::Default)]
63        sorting: Sorting,
64
65        /// Search for palettes with a tag
66        #[arg(long)]
67        tag: Option<String>, // TODO: expand this to perform multiple searches
68    },
69    #[command(about = "Download a color palette")]
70    Download {
71        /// The palette slug (for example: `fairydust-8`)
72        slug: String,
73
74        /// The path to download the file(s) to. Defaults to `<current_directory>/<slug>`
75        #[arg(short, long)]
76        path: Option<PathBuf>,
77
78        /// The output format
79        #[arg(short, long)]
80        format: Format,
81
82        /// The output file size, no-op if the format is not "png"
83        #[arg(short, long)]
84        size: Option<PngSize>,
85    },
86}