honestly not sure what i've done to anger the vcs gods today

i18n
michal 3 years ago
parent 16cbf09d89
commit 52b893a063

@ -16,9 +16,12 @@
### Good Practices ### Good Practices
- Try to use .unwrap() as little as possible - Try to use .unwrap() as little as possible
- Try to never use panic!() in production code, always try to have a possible way to resolve errors, even if it's just unwrap_or/_else() - Try to never use panic!() in production code, always try to have a possible way to resolve errors, even if it's just
- Never use println!() or eprintln!() in finalised code. Using string functions (e.g. info() in Amethyst v3.0.0) is preferred unwrap_or/_else()
- Compartmentalise as much as you can, avoid writing the exact same line of code 50 times if you can turn it into a function - Never use println!() or eprintln!() in finalised code. Using string functions (e.g. info() in Amethyst v3.0.0) is
preferred
- Compartmentalise as much as you can, avoid writing the exact same line of code 50 times if you can turn it into a
function
### Examples of these guidelines in practice ### Examples of these guidelines in practice

@ -32,7 +32,6 @@ Made for Crystal, compatible with any Arch-based Linux distribution.</p>
| 6 | User cancelled package installation | | 6 | User cancelled package installation |
| 7 | Pacman error when installing package | | 7 | Pacman error when installing package |
## How to build: ## How to build:
Tested on latest Cargo (1.60.0-nightly) Tested on latest Cargo (1.60.0-nightly)

@ -3,15 +3,15 @@ use std::path::Path;
use rusqlite::Connection; use rusqlite::Connection;
use crate::internal::rpc::Package;
use crate::{crash, log, Options}; use crate::{crash, log, Options};
use crate::internal::rpc::Package;
pub fn add(pkg: Package, options: Options) { pub fn add(pkg: Package, options: Options) {
let conn = Connection::open(Path::new(&format!( let conn = Connection::open(Path::new(&format!(
"{}/.local/share/ame/db.sqlite", "{}/.local/share/ame/db.sqlite",
env::var("HOME").unwrap() env::var("HOME").unwrap()
))) )))
.expect("Couldn't connect to database"); .expect("Couldn't connect to database");
if options.verbosity >= 1 { if options.verbosity >= 1 {
log(format!("Adding package {} to database", pkg.name)); log(format!("Adding package {} to database", pkg.name));

@ -31,8 +31,8 @@ pub fn init(options: Options) {
)", )",
[], [],
) )
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
crash(format!("Couldn't initialise database: {}", e), 3); crash(format!("Couldn't initialise database: {}", e), 3);
1 1
}); });
} }

@ -3,8 +3,8 @@ use std::path::Path;
use rusqlite::Connection; use rusqlite::Connection;
use crate::internal::rpc::Package;
use crate::{log, Options}; use crate::{log, Options};
use crate::internal::rpc::Package;
pub fn query(options: Options) -> Vec<Package> { pub fn query(options: Options) -> Vec<Package> {
let verbosity = options.verbosity; let verbosity = options.verbosity;
@ -17,7 +17,7 @@ pub fn query(options: Options) -> Vec<Package> {
"{}/.local/share/ame/db.sqlite", "{}/.local/share/ame/db.sqlite",
env::var("HOME").unwrap() env::var("HOME").unwrap()
))) )))
.expect("Couldn't connect to database"); .expect("Couldn't connect to database");
if verbosity >= 1 { if verbosity >= 1 {
log("Querying database for input".to_string()); log("Querying database for input".to_string());

@ -10,7 +10,7 @@ pub fn remove(pkg: &str, options: Options) {
"{}/.local/share/ame/db.sqlite", "{}/.local/share/ame/db.sqlite",
env::var("HOME").unwrap() env::var("HOME").unwrap()
))) )))
.expect("Couldn't connect to database"); .expect("Couldn't connect to database");
let verbosity = options.verbosity; let verbosity = options.verbosity;
@ -26,5 +26,5 @@ pub fn remove(pkg: &str, options: Options) {
WHERE name = ?);", WHERE name = ?);",
[pkg], [pkg],
) )
.expect("Couldn't delete package from database"); .expect("Couldn't delete package from database");
} }

@ -1,7 +1,7 @@
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::internal::strings::log;
use crate::internal::{clean, rpc, structs}; use crate::internal::{clean, rpc, structs};
use crate::internal::strings::log;
use crate::Options; use crate::Options;
pub fn sort(input: &[String], options: Options) -> structs::Sorted { pub fn sort(input: &[String], options: Options) -> structs::Sorted {

@ -1,8 +1,8 @@
use std::{env, io};
use std::io::Write; use std::io::Write;
use std::process::exit; use std::process::exit;
use std::str::FromStr; use std::str::FromStr;
use std::time::UNIX_EPOCH; use std::time::UNIX_EPOCH;
use std::{env, io};
use crate::uwu; use crate::uwu;

@ -199,9 +199,9 @@ fn main() {
.unwrap() .unwrap()
.is_present("repo") .is_present("repo")
&& !matches && !matches
.subcommand_matches("search") .subcommand_matches("search")
.unwrap() .unwrap()
.is_present("aur") .is_present("aur")
{ {
info(format!("Searching AUR and repos for {}", &packages[0])); info(format!("Searching AUR and repos for {}", &packages[0]));
operations::search(&packages[0], options); operations::search(&packages[0], options);

@ -4,9 +4,9 @@ use std::fs::remove_dir_all;
use std::path::Path; use std::path::Path;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::internal::rpc::rpcinfo;
use crate::internal::{crash, prompt};
use crate::{info, log, Options}; use crate::{info, log, Options};
use crate::internal::{crash, prompt};
use crate::internal::rpc::rpcinfo;
pub fn aur_install(a: Vec<String>, options: Options) { pub fn aur_install(a: Vec<String>, options: Options) {
let url = crate::internal::rpc::URL; let url = crate::internal::rpc::URL;

@ -1,7 +1,7 @@
use std::process::Command; use std::process::Command;
use crate::internal::rpc::rpcsearch;
use crate::{log, Options}; use crate::{log, Options};
use crate::internal::rpc::rpcsearch;
pub fn aur_search(a: &str, options: Options) { pub fn aur_search(a: &str, options: Options) {
let verbosity = options.verbosity; let verbosity = options.verbosity;

@ -1,5 +1,5 @@
use std::path::Path;
use std::{env, fs}; use std::{env, fs};
use std::path::Path;
use crate::{log, Options}; use crate::{log, Options};
@ -39,7 +39,7 @@ pub fn uninstall(mut a: Vec<String>, options: Options) {
env::var("HOME").unwrap(), env::var("HOME").unwrap(),
b b
))) )))
.unwrap(); .unwrap();
} }
} }
} }

@ -1,8 +1,8 @@
use runas::Command; use runas::Command;
use crate::{info, log, Options};
use crate::internal::rpc::rpcinfo; use crate::internal::rpc::rpcinfo;
use crate::operations::aur_install::aur_install; use crate::operations::aur_install::aur_install;
use crate::{info, log, Options};
pub fn upgrade(options: Options) { pub fn upgrade(options: Options) {
let verbosity = options.verbosity; let verbosity = options.verbosity;

Loading…
Cancel
Save