shell completion, fixed search, cargo.toml stuff

i18n
michal 2 years ago
parent f045f86f3e
commit f7f3a3e866

@ -1,16 +1,19 @@
[package]
name = "ame"
name = "Amethyst"
version = "3.0.0"
authors = [ "jnats <michal@tar.black>", "axtlos <axtlos@tar.black>" ]
edition = "2021"
description = "A fast and efficient aur helper."
license-file = "LICENSE.md"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "ame"
path = "src/main.rs"
[dependencies]
clap = "2.34.0"
regex = "1.5.4"
clap = { version = "2.34.0", default-features = false, features = [ "suggestions"] }
regex = { version = "1.5.4", default-features = false, features = [ "std" ] }
runas = "0.2.1"
rusqlite = "0.26.3"
rusqlite = { version = "0.26.3", default-features = false }
reqwest = { version = "0.11.7", default-features = false, features = [ "blocking", "json", "default-tls" ] }
serde = { version = "1.0.90", default-features = false, features = [ "derive", "serde_derive" ] }

@ -0,0 +1,18 @@
The Nolicense
Revision 2.1 - Monday 15th November 2021
Copyright (c) 2022 Crystal Linux Team
Everyone is permitted to freely copy and distribute this license document.
Modified redistributions are subject to the following license agreement.
The Nolicense terms and conditions for copying, distribution and modification of software and any created assets are as follows:
- Any unmodified redistributions in either source code or binary form must retain this copyright notice in its entirety.
- Any and all redistributions or derivative works, whether modified or unmodified, must credit the original author(s) of the source code, and provide an easily accessible way to find the original author's source code, wherever it may be published.
- Derivative works and modified redistributions cannot be published under the same name as the original software, nor can it be presented as an extension of or newer revision of said software, and unless explicitly permitted, the original authors name(s) shall not be used to endorse said derivative works.
This software is provided as-is; Neither the copyright holders nor any contributors to the software are to be held liable for any damages caused by any files attached.
By modifying or redistributing the software in any way, you automatically agree to the terms of the license agreement.

@ -22,10 +22,10 @@ pub fn query(a: &str, options: Options) -> Vec<Package> {
}
let mut rs = conn
.prepare("SELECT name, version, description, depends, make_depends FROM packages WHERE name LIKE \"?\"")
.prepare("SELECT name, version, description, depends, make_depends FROM packages WHERE name LIKE :a;")
.unwrap();
let packages_iter = rs
.query_map([a], |row| {
.query_map(&[(":a", &a)], |row| {
Ok(Package {
name: row.get(0).unwrap(),
version: row.get(1).unwrap(),

@ -3,7 +3,8 @@ mod internal;
mod operations;
use crate::internal::{init, sort, structs::Options};
use clap::{App, AppSettings, Arg, ArgSettings, SubCommand};
use clap::{App, AppSettings, Arg, ArgMatches, ArgSettings, Shell, SubCommand};
use std::io;
use std::process::exit;
fn main() {
@ -15,83 +16,100 @@ fn main() {
panic!("Running amethyst as root is disallowed as it can lead to system breakage. Instead, amethyst will prompt you when it needs superuser permissions")
}
let matches = App::new("Amethyst")
.version(env!("CARGO_PKG_VERSION"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.arg(
Arg::with_name("verbose")
.short("v")
.long("verbose")
.multiple(true)
.set(ArgSettings::Global)
.help("Sets the level of verbosity"),
)
.arg(
Arg::with_name("noconfirm")
.long("noconfirm")
.set(ArgSettings::Global)
.help("Complete operation without prompting user"),
)
.subcommand(
SubCommand::with_name("install")
.about("Installs a package from either the AUR or the PacMan-defined repositories")
.aliases(&["-S", "ins"])
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to install")
.required(true)
.multiple(true)
.index(1),
),
)
.subcommand(
SubCommand::with_name("remove")
.about("Removes a previously installed package")
.aliases(&["-R", "-Rs", "rm"])
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to remove")
.required(true)
.multiple(true)
.index(1),
),
)
.subcommand(
SubCommand::with_name("search")
.about("Searches for the relevant packages in both the AUR and repos")
.aliases(&["-Ss", "sea"])
.arg(
Arg::with_name("aur")
.short("a")
.long("aur")
.help("Search only the AUR for the package"),
)
.arg(
Arg::with_name("repo")
.short("r")
.long("repo")
.help("Searches only local repos for the package"),
)
.arg(
Arg::with_name("package(s)")
.help("The name of the package to search for")
.required(true)
.multiple(false)
.index(1),
),
)
.subcommand(
SubCommand::with_name("upgrade")
.about("Upgrades locally installed packages to their latest versions")
.aliases(&["-Syu", "upg"]),
)
.settings(&[
AppSettings::GlobalVersion,
AppSettings::VersionlessSubcommands,
AppSettings::ArgRequiredElseHelp,
AppSettings::InferSubcommands,
])
.get_matches();
fn build_app() -> App<'static, 'static> {
let app = App::new("Amethyst")
.version(env!("CARGO_PKG_VERSION"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.arg(
Arg::with_name("verbose")
.short("v")
.long("verbose")
.multiple(true)
.set(ArgSettings::Global)
.help("Sets the level of verbosity"),
)
.arg(
Arg::with_name("noconfirm")
.long("noconfirm")
.set(ArgSettings::Global)
.help("Complete operation without prompting user"),
)
.subcommand(
SubCommand::with_name("install")
.about(
"Installs a package from either the AUR or the PacMan-defined repositories",
)
.aliases(&["-S", "ins"])
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to install")
.required(true)
.multiple(true)
.index(1),
),
)
.subcommand(
SubCommand::with_name("remove")
.about("Removes a previously installed package")
.aliases(&["-R", "-Rs", "rm"])
.arg(
Arg::with_name("package(s)")
.help("The name of the package(s) to remove")
.required(true)
.multiple(true)
.index(1),
),
)
.subcommand(
SubCommand::with_name("search")
.about("Searches for the relevant packages in both the AUR and repos")
.aliases(&["-Ss", "sea"])
.arg(
Arg::with_name("aur")
.short("a")
.long("aur")
.help("Search only the AUR for the package"),
)
.arg(
Arg::with_name("repo")
.short("r")
.long("repo")
.help("Searches only local repos for the package"),
)
.arg(
Arg::with_name("package(s)")
.help("The name of the package to search for")
.required(true)
.multiple(false)
.index(1),
),
)
.subcommand(
SubCommand::with_name("upgrade")
.about("Upgrades locally installed packages to their latest versions")
.aliases(&["-Syu", "upg"]),
)
.subcommand(
SubCommand::with_name("compgen")
.about("Generates shell completions for given shell (bash by default)")
.aliases(&["-G", "cg"])
.arg(
Arg::with_name("shell")
.help("The name of the shell you want to generate completions for")
.possible_values(&["bash", "fish", "zsh", "pwsh", "elvish"])
.required(true),
),
)
.settings(&[
AppSettings::GlobalVersion,
AppSettings::VersionlessSubcommands,
AppSettings::ArgRequiredElseHelp,
AppSettings::InferSubcommands,
]);
app
}
let matches = build_app().get_matches();
let verbosity: i32 = matches.occurrences_of("verbose") as i32;
let noconfirm: bool = matches.is_present("noconfirm");
@ -104,17 +122,19 @@ fn main() {
init(options);
let packages: Vec<String> = matches
.subcommand()
.1
.unwrap()
.values_of("package(s)")
.unwrap()
.into_iter()
.map(|s| s.to_string())
.collect();
fn collect_matches(a: &ArgMatches) -> Vec<String> {
a.subcommand()
.1
.unwrap()
.values_of("package(s)")
.unwrap()
.into_iter()
.map(|s| s.to_string())
.collect()
}
if let true = matches.is_present("install") {
let packages = collect_matches(&matches);
let sorted = sort(&packages, options);
if !sorted.repo.is_empty() {
@ -133,6 +153,7 @@ fn main() {
}
if let true = matches.is_present("remove") {
let packages = collect_matches(&matches);
operations::uninstall(packages, options);
exit(0);
}
@ -143,6 +164,7 @@ fn main() {
}
if let true = matches.is_present("search") {
let packages = collect_matches(&matches);
if matches
.subcommand_matches("search")
.unwrap()
@ -172,4 +194,30 @@ fn main() {
}
exit(0);
}
if let true = &matches.is_present("compgen") {
let mut app = build_app();
match matches
.subcommand_matches("compgen")
.unwrap()
.value_of("shell")
.unwrap()
{
"bash" => {
app.gen_completions_to("ame", Shell::Bash, &mut io::stdout());
}
"fish" => {
app.gen_completions_to("ame", Shell::Fish, &mut io::stdout());
}
"zsh" => {
app.gen_completions_to("ame", Shell::Zsh, &mut io::stdout());
}
"pwsh" => {
app.gen_completions_to("ame", Shell::PowerShell, &mut io::stdout());
}
"elvish" => {
app.gen_completions_to("ame", Shell::Elvish, &mut io::stdout());
}
_ => {}
}
}
}

Loading…
Cancel
Save