Skip to content

ellabellla/fschema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.