Skip to content

Commit

Permalink
v2 (#15)
Browse files Browse the repository at this point in the history
- [ci: 👷 support for arm
Macs](8ee0a3c)
- [feat: ✨ more arguments, less
options](297d3c0)
  • Loading branch information
M1n-74316D65 authored May 14, 2024
2 parents 8ee0a3c + 177c4ce commit 0aba04b
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 306 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pastol"
version = "1.1.0"
version = "2.0.0"
authors = ["M1n-74316D65"]
edition = "2021"
description = "Paste.lol on the command line."
Expand Down
50 changes: 21 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,24 @@

Pastol enables users to interact with Paste.lol service directly from the command line. Pastol allows you to share text and files quickly and conveniently from the CL.

![example](https://github.com/M1n-74316D65/Pastol/assets/54779580/ccfe2741-4ac9-437f-98f0-2a6c762997d1)

## Usage
### Usage

```sh
pastol [FILE] [OPTIONS]
pastol <COMMAND>
```

## Arguments:

- [FILE] Upload a file or update an existing file on the pastebin

## Options
### Commands:

- -t, --title <TITLE> Title of the new pastebin or the title of the pastebin to update.
- -c, --content <CONTENT> Content of the new pastebin or the content of the pastebin to update.
- -d, --download <DOWNLOAD> Download the content of a pastebin.
- -i, --view <VIEW> View the pastebin.
- -r, --remove <REMOVE> Remove a pastebin from the pastebin service.
- -s, --search <SEARCH> Search by title for pastebins
- -l, --list List all the publicly listed pastebins.
- --setuser <SETUSER> Set your username for the pastebin service.
- --setapikey <SETAPIKEY> Set your API key for the pastebin service.
- --setunlist <SETUNLIST> Set to true if you want newly created pastebins to be unlisted by default. (Default: false) [possible values: true, false].
- -h, --help Print help.
- -V, --version Print version.
```
add Create or update a pastebin on the pastebin service
remove || rm - Remove a pastebin on the pastebin service
download || dl - Download a pastebin
list || ls - List all pastebins
view || cat - View the pastebin
search || find - Search by title for pastebins
settings Change settings
help Print this message or the help of the given subcommand(s)
```

## Install

Expand Down Expand Up @@ -148,49 +140,49 @@ pastol [FILE] [OPTIONS]
- Download a pastebin as a file.

```sh
pastol -d example-title-as-apears-on-the-url
pastol download example-title-as-apears-on-the-url
```

- Upload a file with custom title.

```sh
pastol example.txt -t "Example Title"
pastol add example.txt -t "Example Title"
```

- Upload a file with custom content.

```sh
pastol example.txt -c "This is the content of the example file."
pastol add example.txt -c "This is the content of the example file."
```

- Upload a custom.

```sh
pastol -t title-example -c "pastebin content example"
pastol add -t title-example -c "pastebin content example"
```

- Remove a pastebin.

```sh
pastol -r hello-world
pastol remove hello-world
```

- List all listed pastebins.

```sh
pastol -l
pastol list
```

- View the pastebin.

```sh
pastol -v example
pastol view example
```

- Search by title for pastebins.

```sh
pastol -s exa
pastol search exa
```

## Build
Expand Down
38 changes: 20 additions & 18 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,40 @@ install: clean
run-help: build clean
./target/debug/pastol -h
run-listed-true: build clean
./target/debug/pastol --setunlist true
./target/debug/pastol settings --unlist true
run-listed-false: build clean
./target/debug/pastol --setunlist false
./target/debug/pastol settings --unlist false
run-example: build clean
./target/debug/pastol -t example -c "Example content."
./target/debug/pastol add -t example -c "Example content."
run-example-file: run-download clean
./target/debug/pastol example.md
./target/debug/pastol add example.md
run-example-file-title: run-download clean
./target/debug/pastol example.md -t adw
./target/debug/pastol add example.md -t adw
run-example-file-content: run-download clean
./target/debug/pastol example.md -c dwa
./target/debug/pastol add example.md -c dwa
run-example-no-title: build clean
./target/debug/pastol -c example
./target/debug/pastol add -c example
run-example-no-content: build clean
./target/debug/pastol -t example
./target/debug/pastol add -t example
run-exaple-remove: run-example clean
./target/debug/pastol -r example
./target/debug/pastol remove example
run-exaple-remove-fail: build clean
./target/debug/pastol -r exampledwadawdas
./target/debug/pastol remove exampledwadawdas
run-list: build clean
./target/debug/pastol -l
./target/debug/pastol list
run-list-fail: build clean
./target/debug/pastol -l
./target/debug/pastol list
run-search: build clean
./target/debug/pastol -s logi
./target/debug/pastol search logi
run-search-fail: build clean
./target/debug/pastol -s logidwaaaaaaaaaaa
./target/debug/pastol search logidwaaaaaaaaaaa
run-view: run-example clean
./target/debug/pastol -v example
./target/debug/pastol view example
run-view-fail: build clean
./target/debug/pastol -v qZ5pR9KcX7dA2eW3
./target/debug/pastol view qZ5pR9KcX7dA2eW3
run-download: run-example clean
./target/debug/pastol --download example
./target/debug/pastol download example
run-download-fail: build clean
./target/debug/pastol --download qZ5pR9KcX7dA2eW3
./target/debug/pastol download qZ5pR9KcX7dA2eW3
run-remove: run-example clean
./target/debug/pastol remove example
52 changes: 52 additions & 0 deletions src/config_manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use crate::deserializer;
use crate::serializer;

use super::SettingsArgs;

pub fn serialize(user: String, api_key: String, unlist: bool, output: String) {
let result = serializer::serialize(user, api_key, unlist);
match result {
Ok(_config) => {
println!("{} sucessfully set.", output);
}
Err(e) => {
eprintln!("Error loading config: {}", e);
}
}
}

pub fn check_user_and_api(args: &SettingsArgs, config: deserializer::Config) {
serialize(
if args.user.is_some() {
args.user.clone().unwrap()
} else {
config.user.clone()
},
if args.apikey.is_some() {
args.apikey.clone().unwrap()
} else {
config.api_key.clone()
},
if args.unlist.is_some() {
args.unlist.unwrap()
} else {
config.unlist
},
"".to_string()
+ if args.user.is_some() { "User" } else { "" }
+ if args.apikey.is_some() {
if args.user.is_some() {
", api"
} else {
"Api"
}
} else {
""
}
+ if args.user.is_some() || args.apikey.is_some() {
" and unlist"
} else {
"Unlist"
},
);
}
2 changes: 1 addition & 1 deletion src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde_derive::Deserialize;
use std::fs::File;
use std::io::{self, prelude::*};
// Define a struct to hold your configuration
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
pub struct Config {
pub user: String,
pub api_key: String,
Expand Down
Loading

0 comments on commit 0aba04b

Please sign in to comment.