commit a260f7a4c94a0a20e0168ba7ef9aae705a25c3a9 Author: Ivan Bushchik Date: Sun Mar 19 17:56:11 2023 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 0000000..2991ec0 --- /dev/null +++ b/.rustfmt.toml @@ -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" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..aa750f0 --- /dev/null +++ b/Cargo.toml @@ -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" \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e5e9014 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/responses.json b/responses.json new file mode 100644 index 0000000..7942b89 --- /dev/null +++ b/responses.json @@ -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" + ] +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..30ace28 --- /dev/null +++ b/src/main.rs @@ -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, + negative: Vec, +} + +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> { + 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 { + std::env::var(env_var) + .unwrap_or_else(|_| default.to_owned()) + .split('/') + .map(|s| s.to_owned()) + .collect() +}