GithubHelp home page GithubHelp logo

ellabellla / fschema Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 36 KB

Define a file system structure using json.

License: MIT License

Rust 100.00%
json directory directory-tree file file-tree filesystem rust schema

fschema's Introduction

FSchema

Define a file system structure using json. Only works on linux.

The Schema

{
    "prebuild": [],
    "root": {},
    "postbuild": []
}

The schema at at it's most basic level is made up of a json object with 3 properties; "prebuild", "root", and "postbuild". "prebuild" and "postbuild" are arrays of commands to execute before and after the file system structure has been constructed. "root" is an object containing the directories and files to be created.

A directory is an object where the keys are the names of the files/directories and the values are the files/directories data.

{
    "root": {
        "directory": {

        }
    }
}

A file is an array containing the data of the file, as a sting, and an optional object containing file properties. The first string will be treated as the data and the first object will be treated as the file properties. Any addition elements in the array will be ignored. This is useful for creating comments.

{
    "root": {
        "file" : [ "data", { "ftype": "Text" } ]
    }
}

Files can be supplied with 4 different properties:

  • "mode" defines what permissions a file should be created with as an octal.
  • "defer" defines when the file should be created. Files with lower "defer" properties will be created before files with higher "defer" properties. The default "defer" value is 0
  • "ftype" defines how the file data should be treated. The default "ftype" is "Text".
    • "Text" type treats the file data as the text inside the file.
    • "Copy" type will treat the file data as the path of a file to be copied for this file.
    • "Piped" type treats the file data as a command and will pipe the output of the command into the file.
    • "Link" type will treat the file data as a path of a file to be symbolically linked for this file.
    • "Hex" type will treat the file data as a hex representation of bytes
    • "Bits" type will treat the file data as a string bits
  • "internal" will defines whether the path given by the files data should be treated as a relative path to the filesystem's root path or not (only works with "ftype"s that treat file data as paths)
{
    "ftype": "",
    "mode": "777",
    "defer": 0,
    "internal": false,
}

A directory may also contain comment entries. A comment entries has the value of a string and will be ignored.

{
    "root": {
        "comment": "a comment"
    }
}

The library

Loading a schema

let file = File::open("schema.json").unwrap();
let schema = FSchema::from_reader(file).unwrap();
let schema - FSchema::from_str(json_string).unwrap();

Creating a filesystem structure based on a schema

let root_path = PathBuf::from_str("/path/to/output/directory").unwrap();
schema.create(root_path).unwrap();

The Binary

Usage: fschema <SCHEMA> [OUTPUT]

Arguments:
  <SCHEMA>  Schema
  [OUTPUT]  Output Directory

Options:
  -h, --help     Print help information
  -V, --version  Print version information

License

This software is provided under the MIT license. Click here to view.

fschema's People

Contributors

ellabellla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.