mirror of
https://github.com/ivabus/cargo-makima
synced 2024-12-05 04:55:08 +03:00
Initial commit
This commit is contained in:
commit
a260f7a4c9
6 changed files with 132 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
10
.rustfmt.toml
Normal file
10
.rustfmt.toml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
edition = "2021"
|
||||||
|
hard_tabs = true
|
||||||
|
merge_derives = true
|
||||||
|
reorder_imports = true
|
||||||
|
reorder_modules = true
|
||||||
|
use_field_init_shorthand = true
|
||||||
|
use_small_heuristics = "Off"
|
||||||
|
wrap_comments = true
|
||||||
|
comment_width = 80
|
||||||
|
indent_style = "Block"
|
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
description = "Makima's here to abuse you when running cargo~"
|
||||||
|
repository = "https://github.com/ivabus/cargo-makima"
|
||||||
|
license = "MIT"
|
||||||
|
name = "cargo-makima"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rand = { version = "0.8.5" }
|
||||||
|
serde = { version = "1.0.151", features = ["derive"] }
|
||||||
|
serde_json = "1.0.91"
|
20
LICENSE
Normal file
20
LICENSE
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 Ivan Bushchik
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||||
|
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||||
|
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
responses.json
Normal file
22
responses.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"positive": [
|
||||||
|
"Give paw",
|
||||||
|
"Good boy",
|
||||||
|
"Roll over️",
|
||||||
|
"You don't have to think about a thing. Just trust me, okay?️",
|
||||||
|
"Your hands are cold again. Let's go inside.️",
|
||||||
|
"We’ll be working together until death do us apart",
|
||||||
|
],
|
||||||
|
"negative": [
|
||||||
|
"You want to become a dog?",
|
||||||
|
"Didn't we say that dogs aren't supposed to think?",
|
||||||
|
"Open it. ",
|
||||||
|
"You don't have to think about a thing. Just trust me, okay?",
|
||||||
|
"What could I do to absolutely deny you of a normal life?️",
|
||||||
|
"I gave you a job. I have you money. I gave you lots of good food to eat. I even prepared you a family that I thought you would get along nicely with. I made that kind of happiness become your normalcy, so that I could destroy it all.",
|
||||||
|
"From now on, any happiness you feel, any semblance of normal life you may experience, will all be created by me, and it will all be destroyed by me.",
|
||||||
|
"Your dad's death. It wasn't suicide. You killed him, didn't you?",
|
||||||
|
"A human like you couldn't even wish for a normal life, could he?",
|
||||||
|
"The necessary evil you speak of, is just an excuse to justify the evil things you do. Society has no need for that excuse"
|
||||||
|
]
|
||||||
|
}
|
67
src/main.rs
Normal file
67
src/main.rs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
#![allow(clippy::let_and_return)]
|
||||||
|
|
||||||
|
use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
const RESPONSES: &str = include_str!("../responses.json");
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
struct Responses {
|
||||||
|
positive: Vec<String>,
|
||||||
|
negative: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ResponseType {
|
||||||
|
Positive,
|
||||||
|
Negative,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let code = real_main().unwrap_or_else(|e| {
|
||||||
|
eprintln!("Error: {:?}", e);
|
||||||
|
-1
|
||||||
|
});
|
||||||
|
std::process::exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn real_main() -> Result<i32, Box<dyn std::error::Error>> {
|
||||||
|
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
|
||||||
|
let mut arg_iter = std::env::args();
|
||||||
|
let _cargo = arg_iter.next();
|
||||||
|
|
||||||
|
let mut cmd = std::process::Command::new(cargo);
|
||||||
|
cmd.args(arg_iter);
|
||||||
|
let status = cmd.status()?;
|
||||||
|
eprintln!("\x1b[1m");
|
||||||
|
if status.success() {
|
||||||
|
eprintln!("{}", select_response(ResponseType::Positive))
|
||||||
|
} else {
|
||||||
|
eprintln!("{}", select_response(ResponseType::Negative));
|
||||||
|
}
|
||||||
|
eprintln!("\x1b[0m");
|
||||||
|
Ok(status.code().unwrap_or(-1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn select_response(response_type: ResponseType) -> String {
|
||||||
|
let mut rng = StdRng::from_entropy();
|
||||||
|
|
||||||
|
// Choose what mommy will say~
|
||||||
|
let responses: Responses = serde_json::from_str(RESPONSES).expect("RESPONSES to be valid JSON");
|
||||||
|
|
||||||
|
let response = match response_type {
|
||||||
|
ResponseType::Positive => &responses.positive,
|
||||||
|
ResponseType::Negative => &responses.negative,
|
||||||
|
}
|
||||||
|
.choose(&mut rng)
|
||||||
|
.expect("non-zero amount of responses");
|
||||||
|
// Done~!
|
||||||
|
response.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_options(env_var: &str, default: &str) -> Vec<String> {
|
||||||
|
std::env::var(env_var)
|
||||||
|
.unwrap_or_else(|_| default.to_owned())
|
||||||
|
.split('/')
|
||||||
|
.map(|s| s.to_owned())
|
||||||
|
.collect()
|
||||||
|
}
|
Loading…
Reference in a new issue