Browse Source

Coding style

master
Adrian Heine 6 years ago
parent
commit
abb6947853
  1. 12
      src/command_runner.rs
  2. 5
      src/factory.rs
  3. 2
      src/loggers.rs
  4. 2
      src/repository.rs
  5. 18
      src/schema.rs
  6. 2
      src/storage.rs
  7. 5
      src/symbols/acme/account_key.rs
  8. 5
      src/symbols/acme/cert.rs
  9. 5
      src/symbols/acme/chain.rs
  10. 2
      src/symbols/dir.rs
  11. 9
      src/symbols/factory.rs
  12. 5
      src/symbols/file.rs
  13. 7
      src/symbols/git/checkout.rs
  14. 7
      src/symbols/git/submodules.rs
  15. 4
      src/symbols/hook.rs
  16. 12
      src/symbols/list.rs
  17. 6
      src/symbols/mariadb/database.rs
  18. 6
      src/symbols/mariadb/database_dump.rs
  19. 5
      src/symbols/mariadb/user.rs
  20. 4
      src/symbols/mod.rs
  21. 8
      src/symbols/nginx/server.rs
  22. 5
      src/symbols/npm.rs
  23. 2
      src/symbols/owner.rs
  24. 7
      src/symbols/stored_directory.rs
  25. 20
      src/symbols/systemd/node_js_user_service.rs
  26. 5
      src/symbols/systemd/reload.rs
  27. 11
      src/symbols/systemd/user_session.rs
  28. 5
      src/symbols/tls/csr.rs
  29. 5
      src/symbols/tls/key.rs
  30. 5
      src/symbols/tls/self_signed_cert.rs
  31. 18
      src/symbols/user.rs
  32. 6
      src/symbols/wordpress/plugin.rs
  33. 10
      src/symbols/wordpress/translation.rs

12
src/command_runner.rs

@ -51,10 +51,7 @@ pub struct SetuidCommandRunner<'a, C> where C: 'a + CommandRunner {
impl<'a, C> SetuidCommandRunner<'a, C> where C: 'a + CommandRunner {
pub fn new(user_name: &'a str, command_runner: &'a C) -> SetuidCommandRunner<'a, C> {
SetuidCommandRunner {
command_runner: command_runner,
user_name: user_name
}
SetuidCommandRunner { command_runner, user_name }
}
}
@ -68,7 +65,7 @@ impl<'a> TempSetEnv<'a> {
fn new(name: &'a str, new_value: String) -> TempSetEnv<'a> {
let old_value = env::var(name);
env::set_var(name, new_value);
TempSetEnv { name: name, old_value: old_value.ok() }
TempSetEnv { name, old_value: old_value.ok() }
}
}
@ -101,10 +98,7 @@ pub struct SuCommandRunner<'a, C> where C: 'a + CommandRunner {
impl<'a, C> SuCommandRunner<'a, C> where C: 'a + CommandRunner {
pub fn new(user_name: &'a str, command_runner: &'a C) -> SuCommandRunner<'a, C> {
SuCommandRunner {
command_runner: command_runner,
user_name: user_name
}
SuCommandRunner { command_runner, user_name }
}
}

5
src/factory.rs

@ -14,12 +14,13 @@ use symbols::tls::{TlsCsr, TlsKey};
use symbols::user::{User, UserAdder};
use symbols::user::SystemUserAdder;
#[derive(Default)]
pub struct Factory {
}
impl Factory {
pub fn new() -> Self {
Self {}
Default::default()
}
pub fn get_repo<'a, CR: CommandRunner>(&self, command_runner: &'a CR) -> DefaultSymbolRepository<'a, SystemUserAdder<'a, CR>, CR> {
@ -47,7 +48,7 @@ pub struct DefaultSymbolRepository<'a, A: 'a + UserAdder, C: 'a + CommandRunner>
impl<'a, C: 'a + CommandRunner> DefaultSymbolRepository<'a, SystemUserAdder<'a, C>, C> {
pub fn new(command_runner: &'a C) -> Self {
Self {
command_runner: command_runner,
command_runner,
user_adder: SystemUserAdder::new(command_runner),
home: Regex::new("^/home/([^/]+)$").unwrap(),
home_config: Regex::new("^/home/([^/]+)/.config(?:/|$)").unwrap(),

2
src/loggers.rs

@ -23,7 +23,7 @@ pub struct FilteringLogger<'a> {
impl<'a> FilteringLogger<'a> {
pub fn new(logger: &'a mut Logger) -> Self {
FilteringLogger { logger: logger }
FilteringLogger { logger }
}
}

2
src/repository.rs

@ -19,7 +19,7 @@ pub struct DispatchingSymbolRepository<'a> {
impl<'a> DispatchingSymbolRepository<'a> {
pub fn new(repositories: HashMap<&'a str, Box<SymbolRepository<'a> + 'a>>) -> Self {
DispatchingSymbolRepository { repositories: repositories }
DispatchingSymbolRepository { repositories }
}
}

18
src/schema.rs

@ -15,14 +15,14 @@ pub enum SymbolRunError {
impl Error for SymbolRunError {
fn description(&self) -> &str {
match self {
&SymbolRunError::Symbol(_) => "Symbol execution error",
&SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol"
SymbolRunError::Symbol(_) => "Symbol execution error",
SymbolRunError::ExecuteDidNotReach(_) => "Target not reached after executing symbol"
}
}
fn cause(&self) -> Option<&Error> {
match self {
&SymbolRunError::Symbol(ref e) => Some(&**e),
&SymbolRunError::ExecuteDidNotReach(_) => None
SymbolRunError::Symbol(ref e) => Some(&**e),
SymbolRunError::ExecuteDidNotReach(_) => None
}
}
}
@ -30,8 +30,8 @@ impl Error for SymbolRunError {
impl fmt::Display for SymbolRunError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
&SymbolRunError::Symbol(ref e) => write!(f, "{}", e),
&SymbolRunError::ExecuteDidNotReach(_) => write!(f, "{}", self.description())
SymbolRunError::Symbol(ref e) => write!(f, "{}", e),
SymbolRunError::ExecuteDidNotReach(_) => write!(f, "{}", self.description())
}
}
}
@ -104,11 +104,11 @@ impl<'a, R, L> SymbolRunner for ReportingSymbolRunner<'a, R, L> where R: SymbolR
let mut logger = self.1.borrow_mut();
logger.debug(format!("Running symbol {}", symbol).as_str());
let res = self.0.run_symbol(symbol);
match &res {
&Err(ref e) => {
match res {
Err(ref e) => {
logger.write(format!("Failed on {} with {}, aborting.", symbol, e).as_str());
},
&Ok(_) => {
Ok(_) => {
logger.debug(format!("Successfully finished {}", symbol).as_str());
}
}

2
src/storage.rs

@ -39,6 +39,6 @@ impl Storage for SimpleStorage {
try!(read_dir(dir))
.map(|entry| entry.ok().and_then(|e| e.file_name().into_string().ok()).and_then(|filename| u64::from_str(&filename).ok()))
.fold(None, |maybe_newest, maybe_time| maybe_newest.into_iter().chain(maybe_time).max())
.ok_or("Not found".to_string().into())
.ok_or_else(|| "Not found".to_string().into())
}
}

5
src/symbols/acme/account_key.rs

@ -14,10 +14,7 @@ pub struct AcmeAccountKey<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> AcmeAccountKey<'a, C> {
pub fn new(path: Cow<'a, Path>, command_runner: &'a C) -> Self {
AcmeAccountKey {
path: path,
command_runner: command_runner
}
AcmeAccountKey { path, command_runner }
}
fn get_bytes(&self) -> u32 {

5
src/symbols/acme/cert.rs

@ -16,10 +16,7 @@ pub struct AcmeCert<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> AcmeCert<'a, C> {
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
AcmeCert {
domain: domain,
command_runner: command_runner
}
AcmeCert { domain, command_runner }
}
fn get_csr_path(&self) -> String {

5
src/symbols/acme/chain.rs

@ -16,10 +16,7 @@ pub struct AcmeCertChain<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> AcmeCertChain<'a, C> {
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
AcmeCertChain {
domain: domain,
command_runner: command_runner
}
AcmeCertChain { domain, command_runner }
}
fn get_single_cert_path(&self) -> String {

2
src/symbols/dir.rs

@ -13,7 +13,7 @@ pub struct Dir<D> where D: AsRef<str> {
impl<D> Dir<D> where D: AsRef<str> {
pub fn new(path: D) -> Self {
Dir { path: path }
Dir { path }
}
}

9
src/symbols/factory.rs

@ -25,7 +25,7 @@ pub struct DefaultPolicy;
impl Policy for DefaultPolicy {
fn user_name_for_host(&self, host_name: &'static str) -> String {
host_name.split('.').rev().fold(String::new(), |result, part| if result.len() > 0 { result + "_" } else { result } + part)
host_name.split('.').rev().fold(String::new(), |result, part| if result.is_empty() { result } else { result + "_" } + part)
}
}
@ -41,12 +41,7 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFact
let acme_user = "acme"; // FIXME: CONFIG
let acme_command_runner = SetuidCommandRunner::new(acme_user, command_runner);
SymbolFactory {
command_runner: command_runner,
acme_command_runner: acme_command_runner,
symbol_runner: symbol_runner,
policy: policy
}
SymbolFactory { command_runner, acme_command_runner, symbol_runner, policy }
}
pub fn get_nginx_acme_server<'a, 'c: 'a, S: 'a + Symbol>(&'c self, host: &'static str, nginx_server_symbol: S) -> Box<Action + 'a> {

5
src/symbols/file.rs

@ -16,10 +16,7 @@ pub struct File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
impl<C, D> File<C, D> where C: Deref<Target=str>, D: AsRef<Path> {
pub fn new(path: D, content: C) -> Self {
File {
path: path,
content: content
}
File { path, content }
}
}

7
src/symbols/git/checkout.rs

@ -16,12 +16,7 @@ pub struct GitCheckout<'a, C: 'a + CommandRunner, T: AsRef<str>> {
impl<'a, C: CommandRunner, T: AsRef<str>> GitCheckout<'a, C, T> {
pub fn new(target: T, source: &'a str, branch: &'a str, command_runner: &'a C) -> Self {
GitCheckout {
target: target,
source: source,
branch: branch,
command_runner: command_runner
}
GitCheckout { target, source, branch, command_runner }
}
}

7
src/symbols/git/submodules.rs

@ -12,10 +12,7 @@ pub struct GitSubmodules<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> GitSubmodules<'a, C> {
pub fn new(target: &'a str, command_runner: &'a C) -> Self {
GitSubmodules {
target: target,
command_runner: command_runner
}
GitSubmodules { target, command_runner }
}
}
@ -39,7 +36,7 @@ impl<'a, C: CommandRunner> Symbol for GitSubmodules<'a, C> {
return Ok(false);
}
let output = try!(String::from_utf8(try!(self._run_in_target_repo(&["submodule", "status"]))));
Ok(output.lines().all(|line| line.len() == 0 || line.starts_with(' ')))
Ok(output.lines().all(|line| line.is_empty() || line.starts_with(' ')))
}
fn execute(&self) -> Result<(), Box<Error>> {

4
src/symbols/hook.rs

@ -12,7 +12,7 @@ pub struct Hook<A, B> where A: Symbol, B: Symbol {
// A and B are executed if either A or B are not reached
impl<A, B> Hook<A, B> where A: Symbol, B: Symbol {
pub fn new(a: A, b: B) -> Self {
Hook { a: a, b: b }
Hook { a, b }
}
}
@ -41,7 +41,7 @@ impl<A, B> Symbol for Hook<A, B> where A: Symbol, B: Symbol {
if let Some(provides) = self.b.provides() {
r.extend(provides.into_iter());
}
if r.len() > 0 { Some(r) } else { None }
if r.is_empty() { None } else { Some(r) }
}
fn as_action<'a>(&'a self, runner: &'a SymbolRunner) -> Box<Action + 'a> {

12
src/symbols/list.rs

@ -10,7 +10,7 @@ pub struct List<'a> {
impl<'a> List<'a> {
pub fn new(symbols: Vec<Box<Symbol + 'a>>) -> Self {
List { symbols: symbols }
List { symbols }
}
}
@ -48,7 +48,7 @@ impl<'a> Symbol for List<'a> {
r.extend(provides.into_iter());
}
}
if r.len() > 0 { Some(r) } else { None }
if r.is_empty() { None } else { Some(r) }
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
@ -62,12 +62,12 @@ impl<'a> Symbol for List<'a> {
struct SymbolListAction<'a> {
runner: &'a SymbolRunner,
symbols: &'a Vec<Box<Symbol + 'a>>
symbols: &'a [Box<Symbol + 'a>]
}
impl<'a> SymbolListAction<'a> {
fn new(runner: &'a SymbolRunner, symbols: &'a Vec<Box<Symbol + 'a>>) -> Self {
Self { runner: runner, symbols: symbols }
fn new(runner: &'a SymbolRunner, symbols: &'a [Box<Symbol + 'a>]) -> Self {
Self { runner, symbols }
}
}
@ -86,7 +86,7 @@ pub struct ListAction<'a> {
impl<'a> ListAction<'a> {
pub fn new(actions: Vec<Box<Action + 'a>>) -> Self {
Self { actions: actions }
Self { actions }
}
}

6
src/symbols/mariadb/database.rs

@ -13,11 +13,7 @@ pub struct MariaDBDatabase<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> MariaDBDatabase<'a, C> {
pub fn new(db_name: Cow<'a, str>, seed_file: Cow<'a, str>, command_runner: &'a C) -> Self {
MariaDBDatabase {
db_name: db_name,
seed_file: seed_file,
command_runner: command_runner
}
MariaDBDatabase { db_name, seed_file, command_runner }
}
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {

6
src/symbols/mariadb/database_dump.rs

@ -14,11 +14,7 @@ pub struct DatabaseDump<'a, N, C, S> where N: 'a + AsRef<str>, C: 'a + CommandRu
impl<'a, N: AsRef<str>, C: CommandRunner, S: Storage> DatabaseDump<'a, N, C, S> {
pub fn new(db_name: N, storage: S, command_runner: &'a C) -> Self {
DatabaseDump {
db_name: db_name,
storage: storage,
command_runner: command_runner
}
DatabaseDump { db_name, storage, command_runner }
}
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {

5
src/symbols/mariadb/user.rs

@ -13,10 +13,7 @@ pub struct MariaDBUser<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> MariaDBUser<'a, C> {
pub fn new(user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
MariaDBUser {
user_name: user_name,
command_runner: command_runner
}
MariaDBUser { user_name, command_runner }
}
fn run_sql(&self, sql: &str) -> Result<String, Box<Error>> {

4
src/symbols/mod.rs

@ -38,7 +38,7 @@ pub struct SymbolAction<'a, S: Symbol + 'a> {
impl<'a, S: Symbol> SymbolAction<'a, S> {
pub fn new(runner: &'a SymbolRunner, symbol: &'a S) -> Self {
Self { runner: runner, symbol: symbol }
Self { runner, symbol }
}
}
@ -55,7 +55,7 @@ pub struct OwnedSymbolAction<'a, S: Symbol + 'a> {
impl<'a, S: Symbol + 'a> OwnedSymbolAction<'a, S> {
pub fn new(runner: &'a SymbolRunner, symbol: S) -> Self {
Self { runner: runner, symbol: symbol }
Self { runner, symbol }
}
}

8
src/symbols/nginx/server.rs

@ -23,13 +23,13 @@ impl From<io::Error> for NginxServerError<io::Error> {
impl<E: Error> Error for NginxServerError<E> {
fn description(&self) -> &str {
match self {
&NginxServerError::ExecError(ref e) => e.description(),
&NginxServerError::GenericError => "Generic error"
NginxServerError::ExecError(ref e) => e.description(),
NginxServerError::GenericError => "Generic error"
}
}
fn cause(&self) -> Option<&Error> {
match self {
&NginxServerError::ExecError(ref e) => Some(e),
NginxServerError::ExecError(ref e) => Some(e),
_ => None
}
}
@ -123,7 +123,7 @@ location @proxy {{
pub fn new(domain: &'a str, content: String, command_runner: &'a C) -> Self {
let file_path = String::from("/etc/nginx/sites-enabled/") + domain;
NginxServer {
command_runner: command_runner,
command_runner,
file: FileSymbol::new(file_path, content)
}
}

5
src/symbols/npm.rs

@ -12,10 +12,7 @@ pub struct NpmInstall<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> NpmInstall<'a, C> {
pub fn new(target: &'a str, command_runner: &'a C) -> Self {
NpmInstall {
target: target,
command_runner: command_runner
}
NpmInstall { target, command_runner }
}
}

2
src/symbols/owner.rs

@ -19,7 +19,7 @@ pub struct Owner<'a, C: 'a + CommandRunner, D> where D: AsRef<str> {
impl<'a, C: CommandRunner, D> Owner<'a, C, D> where D: AsRef<str> {
pub fn new(path: D, user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
Owner { path: path, user_name: user_name, command_runner: command_runner }
Owner { path, user_name, command_runner }
}
}

7
src/symbols/stored_directory.rs

@ -23,12 +23,7 @@ pub struct StoredDirectory<'a, S, C: 'a + CommandRunner> where S: Storage {
impl<'a, S, C: CommandRunner> StoredDirectory<'a, S, C> where S: Storage {
pub fn new(path: Cow<'a, str>, storage: S, dir: StorageDirection, command_runner: &'a C) -> Self {
StoredDirectory {
path: path,
storage: storage,
dir: dir,
command_runner: command_runner
}
StoredDirectory { path, storage, dir, command_runner }
}
}

20
src/symbols/systemd/node_js_user_service.rs

@ -28,14 +28,14 @@ impl From<io::Error> for NodeJsSystemdUserServiceError<io::Error> {
impl<E: Error> Error for NodeJsSystemdUserServiceError<E> {
fn description(&self) -> &str {
match self {
&NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(),
&NodeJsSystemdUserServiceError::GenericError => "Generic error",
&NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed"
NodeJsSystemdUserServiceError::ExecError(ref e) => e.description(),
NodeJsSystemdUserServiceError::GenericError => "Generic error",
NodeJsSystemdUserServiceError::ActivationFailed(_) => "Activation of service failed"
}
}
fn cause(&self) -> Option<&Error> {
match self {
&NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e),
NodeJsSystemdUserServiceError::ExecError(ref e) => Some(e),
_ => None
}
}
@ -44,7 +44,7 @@ impl<E: Error> Error for NodeJsSystemdUserServiceError<E> {
impl<E: Error> fmt::Display for NodeJsSystemdUserServiceError<E> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(write!(f, "{}", self.description()));
if let &NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self {
if let NodeJsSystemdUserServiceError::ActivationFailed(Ok(ref log)) = self {
try!(write!(f, ": {:?}", log));
};
Ok(())
@ -59,10 +59,10 @@ pub struct NodeJsSystemdUserService<'a, C, R> where C: Deref<Target=str>, R: Com
}
impl<'a, R> NodeJsSystemdUserService<'a, String, SetuidCommandRunner<'a, R>> where R: CommandRunner {
pub fn new(home: &'a str, user_name: &'a str, name: &'a str, path: &'a str, command_runner: &'a R) -> Self {
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), name);
pub fn new(home: &'a str, user_name: &'a str, service_name: &'a str, path: &'a str, command_runner: &'a R) -> Self {
let file_path = format!("{}/.config/systemd/user/{}.service", home.trim_right(), service_name);
let port = format!("/var/tmp/{}-{}.socket", user_name, name);
let port = format!("/var/tmp/{}-{}.socket", user_name, service_name);
let content = format!("[Service]
Environment=NODE_ENV=production
Environment=PORT={1}
@ -81,8 +81,8 @@ WantedBy=default.target
", path, port);
NodeJsSystemdUserService {
service_name: name,
user_name: user_name,
service_name,
user_name,
command_runner: SetuidCommandRunner::new(user_name, command_runner),
file: FileSymbol::new(file_path, content)
}

5
src/symbols/systemd/reload.rs

@ -11,10 +11,7 @@ pub struct ReloadService<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> ReloadService<'a, C> {
pub fn new(service: &'a str, command_runner: &'a C) -> Self {
ReloadService {
service: service,
command_runner: command_runner
}
ReloadService { service, command_runner }
}
}

11
src/symbols/systemd/user_session.rs

@ -15,13 +15,13 @@ pub enum SystemdUserSessionError<E: Error> {
impl<E: Error> Error for SystemdUserSessionError<E> {
fn description(&self) -> &str {
match self {
&SystemdUserSessionError::ExecError(ref e) => e.description(),
&SystemdUserSessionError::GenericError => "Generic error"
SystemdUserSessionError::ExecError(ref e) => e.description(),
SystemdUserSessionError::GenericError => "Generic error"
}
}
fn cause(&self) -> Option<&Error> {
match self {
&SystemdUserSessionError::ExecError(ref e) => Some(e),
SystemdUserSessionError::ExecError(ref e) => Some(e),
_ => None
}
}
@ -40,10 +40,7 @@ pub struct SystemdUserSession<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> SystemdUserSession<'a, C> {
pub fn new(user_name: Cow<'a, str>, command_runner: &'a C) -> Self {
SystemdUserSession {
user_name: user_name,
command_runner: command_runner
}
SystemdUserSession { user_name, command_runner }
}
}

5
src/symbols/tls/csr.rs

@ -14,10 +14,7 @@ pub struct TlsCsr<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> TlsCsr<'a, C> {
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
TlsCsr {
domain: domain,
command_runner: command_runner
}
TlsCsr { domain, command_runner }
}
fn get_key_path(&self) -> String {

5
src/symbols/tls/key.rs

@ -13,10 +13,7 @@ pub struct TlsKey<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> TlsKey<'a, C> {
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
TlsKey {
domain: domain,
command_runner: command_runner
}
TlsKey { domain, command_runner }
}
fn get_path(&self) -> String {

5
src/symbols/tls/self_signed_cert.rs

@ -14,10 +14,7 @@ pub struct SelfSignedTlsCert<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> SelfSignedTlsCert<'a, C> {
pub fn new(domain: Cow<'a, str>, command_runner: &'a C) -> Self {
SelfSignedTlsCert {
domain: domain,
command_runner: command_runner
}
SelfSignedTlsCert { domain, command_runner }
}
fn get_key_path(&self) -> String {

18
src/symbols/user.rs

@ -16,14 +16,14 @@ pub enum UserAdderError {
impl Error for UserAdderError {
fn description(&self) -> &str {
match self {
&UserAdderError::AlreadyExists => "User already exists",
&UserAdderError::UnknownError => "Unknown error",
&UserAdderError::ImplError(_) => "User adding error"
UserAdderError::AlreadyExists => "User already exists",
UserAdderError::UnknownError => "Unknown error",
UserAdderError::ImplError(_) => "User adding error"
}
}
fn cause(&self) -> Option<&Error> {
match self {
&UserAdderError::ImplError(ref e) => Some(e.as_ref()),
UserAdderError::ImplError(ref e) => Some(e.as_ref()),
_ => None
}
}
@ -50,7 +50,7 @@ pub enum UserError {
impl Error for UserError {
fn description(&self) -> &str {
match self {
&UserError::GenericError => "Could not find out if user exists"
UserError::GenericError => "Could not find out if user exists"
}
}
fn cause(&self) -> Option<&Error> {
@ -77,11 +77,7 @@ pub struct User<'a, C: 'a + CommandRunner, A: 'a + UserAdder> {
impl<'a, C: CommandRunner, A: 'a + UserAdder> User<'a, C, A> {
pub fn new(user_name: Cow<'a, str>, command_runner: &'a C, user_adder: &'a A) -> Self {
User {
user_name: user_name,
command_runner: command_runner,
user_adder: user_adder
}
User { user_name, command_runner, user_adder }
}
}
@ -124,7 +120,7 @@ pub struct SystemUserAdder<'a, C: 'a + CommandRunner> {
impl<'a, C: CommandRunner> SystemUserAdder<'a, C> {
pub fn new(command_runner: &'a C) -> Self {
SystemUserAdder { command_runner: command_runner }
SystemUserAdder { command_runner }
}
}

6
src/symbols/wordpress/plugin.rs

@ -19,11 +19,7 @@ pub struct WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: 'a + Command
impl<'a, C, R> WordpressPlugin<'a, C, R> where C: Deref<Target=str>, R: CommandRunner {
pub fn new(base: C, name: C, command_runner: &'a R) -> Self {
WordpressPlugin {
base: base,
name: name,
command_runner: command_runner
}
WordpressPlugin { base, name, command_runner }
}
fn get_path(&self) -> PathBuf {

10
src/symbols/wordpress/translation.rs

@ -22,9 +22,9 @@ impl<'a, C, R> WordpressTranslation<'a, C, String, R> where C: AsRef<str>, R: Co
pub fn new<D: AsRef<str>>(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self {
WordpressTranslation {
path: Path::new(path.as_ref()).join("wp-content/languages").to_string_lossy().to_string(),
version: version,
locale: locale,
command_runner: command_runner
version,
locale,
command_runner
}
}
}
@ -35,8 +35,8 @@ impl<'a, C, D, R> WordpressTranslation<'a, C, D, R> where C: AsRef<str>, D: AsRe
let locale: &str = self.locale.as_ref();
let path_locale = if locale == "de_DE" { "de".to_owned() } else { locale.to_lowercase().replace('_', "-") };
let mut res = vec![];
for &(in_slug, out_slug) in [("", ""), ("cc/", "continents-cities-"), ("admin/", "admin-"), ("admin/network/", "admin-network-")].into_iter() {
for format in ["po", "mo"].into_iter() {
for &(in_slug, out_slug) in [("", ""), ("cc/", "continents-cities-"), ("admin/", "admin-"), ("admin/network/", "admin-network-")].iter() {
for format in ["po", "mo"].iter() {
res.push((
format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format),
format!("{}/{}{}.{}", self.path.as_ref(), out_slug, self.locale.as_ref(), format)

Loading…
Cancel
Save