Browse Source

Added a few (empty) commands

master
Julio Biason 3 years ago
parent
commit
0236dabff0
  1. 2
      src/args/mod.rs
  2. 44
      src/commands/mod.rs

2
src/args/mod.rs

@ -104,6 +104,8 @@ pub fn parse() -> Result<Command, ParsingError> {
} }
_ => unimplemented!(), _ => unimplemented!(),
}, },
("fetch", _) => Ok(Command::fetch(account_name.into())),
("sync", _) => Ok(Command::sync(account_name.into())),
_ => Err(ParsingError::UnknownCommand), _ => Err(ParsingError::UnknownCommand),
} }
} else { } else {

44
src/commands/mod.rs

@ -34,16 +34,16 @@ use crate::storage::markdown::config::MarkdownConfig;
type CommandResult = Result<(), CommandError>; type CommandResult = Result<(), CommandError>;
/// Available Storages /// Available Storages.
#[derive(Debug)] #[derive(Debug)]
pub enum StorageType { pub enum StorageType {
/// Store in the filesystem, as Markdown /// Store in the filesystem, as Markdown.
Markdown, Markdown,
/// Store in the filesystem, as Org-Mode /// Store in the filesystem, as Org-Mode.
Org, Org,
/// Store in Joplin /// Store in Joplin.
Joplin, Joplin,
} }
@ -60,20 +60,26 @@ impl TryFrom<&str> for StorageType {
} }
} }
/// Available commands /// Available commands.
#[derive(Debug)] #[derive(Debug)]
pub enum Command { pub enum Command {
/// Add a new account /// Add a new account.
AddAccount(String), AddAccount(String),
/// Remove an account /// Remove an account.
RemoveAccount(String), RemoveAccount(String),
/// Add a storage in an account /// Add a storage in an account.
AddStorage(String, StorageType), AddStorage(String, StorageType),
/// Fetch favourites from all accounts /// Fetch favourites from all accounts.
FetchAll, FetchAll,
/// Fetch one single account.
Fetch(String),
/// Forces the last favourite to be the current favourite.
Sync(String),
} }
impl Command { impl Command {
@ -93,6 +99,14 @@ impl Command {
Command::FetchAll Command::FetchAll
} }
pub fn fetch(account: &str) -> Self {
Command::Fetch(account.into())
}
pub fn sync(account: &str) -> Self {
Command::Sync(account.into())
}
/// Execute the command, based on its value /// Execute the command, based on its value
pub fn execute(&self) -> CommandResult { pub fn execute(&self) -> CommandResult {
match self { match self {
@ -102,6 +116,8 @@ impl Command {
add_storage(account, storage) add_storage(account, storage)
} }
Command::FetchAll => fetch_all(), Command::FetchAll => fetch_all(),
Command::Fetch(account) => fetch_account(account),
Command::Sync(account) => sync_account(account),
} }
} }
} }
@ -157,7 +173,11 @@ fn fetch_all() -> CommandResult {
Ok(()) Ok(())
} }
fn fetch_account(account: &mut AccountConfig) -> CommandResult { fn fetch_account(account: &str) -> CommandResult {
Ok(())
}
fn fetch_account_favourites(account: &mut AccountConfig) -> CommandResult {
// XXX before anything, we could check if there is any storage enabled. // XXX before anything, we could check if there is any storage enabled.
// XXX we could create a list of storages, so after retrieving the toot // XXX we could create a list of storages, so after retrieving the toot
// and converting to our format, we just go through this list and call // and converting to our format, we just go through this list and call
@ -181,3 +201,7 @@ fn fetch_account(account: &mut AccountConfig) -> CommandResult {
} }
Ok(()) Ok(())
} }
fn sync_account(account: &str) -> CommandResult {
Ok(())
}

Loading…
Cancel
Save