undulate 0.1.0

A lightweight package manager for Lua. An early work in progress, expect nothing to work!
Documentation
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
extern crate reqwest;
extern crate git2;
extern crate tempdir;

use tempdir::TempDir;
use git2::Repository;

use std::io::{self, Read, Write};
use std::path::Path;
use std::fs::{self, File};

pub static PACKAGE_FILENAME: &'static str = "undule.json";

#[derive(Debug)]
pub enum InitError {
    /// Couldn't initialize new undule because `undule.json` already existed.
    AlreadyExists,

    /// Couldn't create `undule.json`
    FailedToCreate,
}

#[derive(Debug)]
pub enum AddError {
}

#[derive(Debug)]
pub enum RemoveError {
}

#[derive(Debug)]
pub enum InstallError {
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct Package {
    name: String,
}

impl Package {
    pub fn new() -> Self {
        Package {
            name: "<package name>".to_string(),
        }
    }
}

impl Default for Package {
    fn default() -> Self {
        Package {
            name: "".to_string(),
        }
    }
}

pub fn init<P: AsRef<Path>>(dir: P) -> Result<(), InitError> {
    let dir = dir.as_ref();
    let package_path = dir.join(PACKAGE_FILENAME);

    match fs::metadata(&package_path) {
        Ok(_) => return Err(InitError::AlreadyExists),
        Err(_) => {},
    }

    let mut file = match File::create(&package_path) {
        Ok(f) => f,
        Err(_) => return Err(InitError::FailedToCreate),
    };

    let package = Package::new();
    let serialized = serde_json::to_string_pretty(&package).unwrap();

    file.write(serialized.as_bytes()).unwrap();

    Ok(())
}

pub fn add<T: AsRef<str>>(specifier: T) -> Result<(), AddError> {
    let specifier = specifier.as_ref();

    if let Ok(dir) = TempDir::new("undulate") {
        let _repo = match Repository::clone(specifier, dir.path()) {
            Ok(repo) => repo,
            Err(e) => panic!("Failed to clone: {}", e),
        };
    }

    Ok(())
}

pub fn remove<T: AsRef<str>>(specifier: T) -> Result<(), RemoveError> {
    Ok(())
}

pub fn install(url: &str) -> Result<(), InstallError> {
    Ok(())
}