wysgy_core 0.1.5

Core libs for wysgy, a command line graph DB
Documentation
use crate::converter::Converter;
use crate::errors::WysgyResult;
use crate::files::{CONFIG_JSON_CONTENTS, GV_TEMPLATE_CONTENTS};
use crate::node::Node;
use crate::rel::Rel;
use glob::glob;
use prettytable::Table;
use serde_json::{json, Value};
use std::cmp::max;
use std::error;
use std::fs;
use std::io::{BufRead, ErrorKind};
use std::path::PathBuf;
use std::process::{Child, Command};

pub struct Wysgy {
    pub path: PathBuf,
    editor: String,
}

// TODO: refactor into
// 1. GRAPH Operations
//  These should be the actual graph operations on the nodes and relations.
//      ex: link nodes, add node, remove node (and all rels with node), remove rel
//          allow multiple links between nodes?
// 2. FILE Operations
//      files naming should be completely indenpendent of graph operations
//      to ensure that, we should not use files naming as part of the file contents
//      ex: saving nodes to files - what should the name of a node be?
//          (i) let user specify - CURRENT
//          (ii) assign a name randomly, generated by time?
//          (iii) assign incrementing numbers as names - n1, n2 - n is a prepending for node
//
//      ex: saving rels to files
//          (i) {src}_{dst} - CURRENT
//          (ii) folder structure named by id (can delete entire folder of n1 when deleting node
//          n2)
//              -- n1
//                  -- n2
//                      -- r1
//                      -- r2
//
//              -- n2
//                  -- n1
//                      -- r1
//                      -- r2
//          (iii)
// 3. API Functions

impl Wysgy {
    // remove node accepts a label aka. filename but how to find this filename is nontrivial now
    // TODO: interface function to translate criteria/requirement of key-values to a list of filenames of nodes
    pub fn remove_node(&self, label: &String) -> Result<(), Box<dyn error::Error>> {
        fs::remove_file(self.node(label))?;
        Ok(())
    }

    pub fn remove_rel(&self, src: &String, dst: &String) -> Result<(), Box<dyn error::Error>> {
        fs::remove_file(self.rel(src, dst).unwrap())?;
        Ok(())
    }
}