Skip to content

Commit

Permalink
feat!: merge userstyles subcommands into root query and init (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter authored Jul 4, 2024
1 parent 33b74a8 commit f39f861
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 622 deletions.
200 changes: 26 additions & 174 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,15 @@ purr <COMMAND> [-h | --help] [-V | --version]
- [`stars`](#stars)
- [`whiskers`](#whiskers)
- [`init`](#init)
- [`userstyles`](#userstyles)
- [`query`](#query-1)
- [`maintained`](#maintained-1)
- [`has`](#has-1)
- [`init`](#init-1)
- [`whiskerify`](#whiskerify)

### `query`

```
purr query [--for <PORT>] [-g | --get] [-c | --count]
purr query [--for <PORT>] [-g | --get] [-c | --count] [--userstyles | --no-userstyles | --only-userstyles]
```

Query the ports.yml data source. With no arguments, all ports are displayed.
Query the ports.yml data source. With no arguments, all ports are displayed. The `--count` and userstyles-related flags work for all of the query subcommands.

<details>
<summary>Examples</summary>
Expand All @@ -56,13 +51,24 @@ Query the ports.yml data source. With no arguments, all ports are displayed.
purr query
```

- List all ports excluding userstyles.

```
purr query --no-userstyles
```

- List all userstyles.

```
purr query --only-userstyles
```

- Count the number of ports.

```
purr query --count
```


- List the names of all ports.

```
Expand Down Expand Up @@ -146,8 +152,11 @@ purr query has [PROPERTIES] [-n | --not] [-c | --count]

- `--name <NAME>`
- `--category <CATEGORIES>`
- `--upstreamed`
- `--platform <PLATFORM>`
- `--icon <ICON>`
- `--color <COLOR>`
- `--alias`
- `--url <URL>`

<details>
Expand Down Expand Up @@ -230,7 +239,7 @@ purr query whiskers [--is <STATE>] [-n | --not] [-c | --count | -p | --percentag
<summary>Examples</summary>

- Get the overall statistics of the Whiskerification process.

```
purr query whiskers
```
Expand All @@ -253,7 +262,7 @@ purr query whiskers [--is <STATE>] [-n | --not] [-c | --count | -p | --percentag
purr query whiskers --is not-applicable
```

- List repositories Whiskers *is* applicable for.
- List repositories Whiskers _is_ applicable for.

```
purr query whiskers --is not-applicable --not
Expand All @@ -266,180 +275,23 @@ purr query whiskers [--is <STATE>] [-n | --not] [-c | --count | -p | --percentag
The `init` command accepts each value (name, categories, etc.) via arguments, though if not provided a series of prompts will be displayed instead.

```
purr init [PROPERTIES]
```

**Properties**:

- `--name <NAME>`
- `--url <URL>`

### `userstyles`

#### `query`

```
purr userstyles query [--for <USERSTYLE>] [-g | --get] [-c | --count]
```

Query the userstyles.yml data source. With no arguments, all userstyles are displayed.

<details>
<summary>Examples</summary>

- List all userstyles.

```
purr userstyles query
```

- Count the number of userstyles.

```
purr userstyles query --count
```


- List the names of all userstyles.

```
purr userstyles query --get name
```

- List the current maintainers of the `youtube` userstyle.

```
purr userstyles query --for youtube --get current-maintainers
```

</details>

##### `maintained`

```
purr userstyles query maintained [--by <NAME>] [-n | --not] [-c | --count]
```

<details>
<summary>Examples</summary>

- List maintained userstyles.

```
purr userstyles query maintained
```

- Count the number of maintained userstyles.

```
purr userstyles query maintained --count
```

- List *un*maintained userstyles.

```
purr userstyles query maintained --not
```

- Count the number of *un*maintained userstyles.

```
purr userstyles query maintained --not --count
```

- List userstyles maintained by `<username>`.

```
purr userstyles query maintained --by "<username>"
```

- Count the number of userstyles maintained by `<username>`.

```
purr userstyles query maintained --by "<username>" --count
```

- List userstyles _not_ maintained by `<username>`.

```
purr userstyles query maintained --by "<username>" --not
```

- Count the number of userstyles _not_ maintained by `<username>`.

```
purr userstyles query maintained --by "<username>" --not --count
```

</details>

##### `has`

```
purr userstyles query has [PROPERTIES] [-n | --not] [-c | --count]
```

**Properties:**

- `--name <NAME>`
- `--category <CATEGORIES>`
- `--icon <ICON>`
- `--color <COLOR>`
- `--app-link <APP_LINK>`

<details>
<summary>Examples</summary>

- List userstyles with `color` set to `mauve`.

```
purr userstyles query has --color mauve
```

- Count the number of userstyles that have `color` set to `mauve`.

```
purr userstyles query has --color mauve --count
```

- Count the number of userstyles that have `color` set to anything other than `mauve`.

```
purr userstyles query has --color mauve --not --count
```

- List userstyles that do not have `icon` defined.

```
purr userstyles query has --icon --not
```

</details>

#### `init`

The `init` command accepts each value (name, categories, etc.) via arguments, though if not provided a series of prompts will be displayed instead.

```
purr userstyles init [PROPERTIES]
purr init <TEMPLATE> [PROPERTIES]
```

**Properties**:

- `--name <NAME>`
- `--category <CATEGORIES>`
- `--icon <ICON>`
- `--color <COLOR>`
- `--app-link <APP_LINK>`
#### Templates

| Template | Available Properties/Flags |
| ----------- | ------------------------------------------ |
| `port` | `name`, `url` |
| `userstyle` | `name`, `category`, `icon`, `color`, `url` |

### `whiskerify`

```
purr whiskerify <PATH> [-o | --output <PATH>]
```

Whiskerify a file by replacing Catppuccin colors and names with Tera expressions. Prints the output or writes to the `--output` file path if passed.
Whiskerify a file by replacing Catppuccin colors and names with Tera expressions. Prints the output or writes to the `--output` file path if given.

## License

Expand Down
57 changes: 26 additions & 31 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::PathBuf;

use clap::{arg, Args, Parser, Subcommand, ValueEnum};
use clap::{arg, ArgAction, Args, Parser, Subcommand, ValueEnum};
use color_eyre::owo_colors::OwoColorize;
use url::Url;

Expand All @@ -19,7 +19,7 @@ pub struct Cli {

#[derive(Subcommand)]
pub enum Commands {
/// Query about the ports.yml data source
/// Query ports and userstyles
Query {
#[command(subcommand)]
command: Option<Query>,
Expand All @@ -35,21 +35,23 @@ pub enum Commands {
/// Extract a specific property each result
#[arg(short, long, value_enum, default_value_t)]
get: Key,
},
/// Initialize a new port from catppuccin/template
Init {
/// Name of the application
#[arg(long)]
name: Option<String>,

/// URL to the application
#[arg(long, value_parser = valid_url)]
url: Option<String>,
// See https://jwodder.github.io/kbits/posts/clap-bool-negate/.
// Cursed code to enable the correct relationship between `--userstyles` and `--no-userstyles`.
/// Include userstyles in query results
#[clap(long = "userstyles", overrides_with = "userstyles", global = true)]
_no_userstyles: bool,
/// Exclude userstyles in query results
#[clap(long = "no-userstyles", action = ArgAction::SetFalse, global = true)]
userstyles: bool,
/// Exclude non-userstyles from query results
#[arg(long, conflicts_with_all = ["userstyles", "_no_userstyles"], global = true)]
only_userstyles: bool,
},
/// Userstyles-related subcommands
Userstyles {
/// Initialize a new port or userstyle
Init {
#[command(subcommand)]
command: Userstyles,
command: Template,
},
/// Convert a theme file to a Whiskers template
Whiskerify {
Expand All @@ -61,26 +63,19 @@ pub enum Commands {
}

#[derive(Subcommand)]
pub enum Userstyles {
/// Query about the userstyles.yml data source
Query {
#[command(subcommand)]
command: Option<UserstylesQuery>,

/// Query data for a specific userstyle
#[arg(long, name = "USERSTYLE", conflicts_with = "count", requires = "get")]
r#for: Option<String>,

/// Count the number of results
#[arg(short, long)]
count: bool,
pub enum Template {
/// Initialize a new port from catppuccin/template
Port {
/// Name of the application
#[arg(long)]
name: Option<String>,

/// Extract a specific property each result
#[arg(short, long, value_enum, default_value_t)]
get: UserstyleKey,
/// URL to the application
#[arg(long, value_parser = valid_url)]
url: Option<String>,
},
/// Initialize a new userstyle from the template
Init {
Userstyle {
/// Name of the application
#[arg(long)]
name: Option<String>,
Expand Down
Loading

0 comments on commit f39f861

Please sign in to comment.