1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Messages sent via IPC client.

use std::io::Error as IOError;

use rustc_serialize::json::{Json, ToJson};

/// Commands sent over command socket
#[derive(Debug, PartialEq, Clone)]
pub enum Command {
    /// Retrieve an item from the API.
    /// Returns a `GotKey` if successful.
    Get(String),
    /// Set an object in way-cooler.
    /// Returns `Success` if successful.
    Set(String, Json),
    /// Run a way-cooler procedure.
    /// Returns `success` if successful.
    Run(String),
    /// Get metadata about a key.
    /// Returns `success` if key found.
    Exists(String),
    /// Gets the version of way-cooler ipc.
    /// Returns `Version`.
    Version,
    /// Gtes a list of commands.
    /// Returns `Commands`.
    Commands,
    /// Run a simple ping of the server.
    Ping,
}

/// Return types from the command socket
/// for successful command queries
#[derive(Debug, PartialEq, Clone)]
pub enum CommandSuccess {
    /// The request was successful
    Success,
    /// A key was found
    GotKey(Json),
    /// The version way-cooler is on,
    Version(u64),
    /// Commands available to the API
    Commands(Vec<String>),
}

/// Return types from the command socket
/// for erroneous command queries
pub enum CommandError {
    /// There was an IO error sending the command/receiving the result
    IO(IOError),
    /// The requested key was not found in way-cooler's API
    KeyNotFound,
    /// The requested key was of the wrong type
    /// (i.e. asked to set a command instead of run)
    InvalidKey,
    /// An unknown error occurred, such as the library sending an
    /// invalid request. Check that way-cooler is using the right version
    UnknownError(Json)
}

/// Result type returned from command thread requests
pub type CommandResult = Result<CommandSuccess, CommandError>;

impl Command {
}