Commit 7d0bf964 authored by Steve Streza's avatar Steve Streza
Browse files

Add custom paths

parent 4bbe212e
#! /usr/bin/env node
import DataStore from "./src/data/database";
import FolderAccessor from "./src/data/accessors/folder";
import { join as joinPath } from "path"
import { homedir } from "os"
import * as Yargs from 'yargs'
const accessor = new FolderAccessor("/tmp/data");
let foo = new DataStore(accessor);
foo = foo;
Yargs
.usage("$0 <command> [args]")
.usage("$0 [opts] <command> [args]")
.env("MICROJOURNAL")
.option("path", {
alias: "p",
default: joinPath(homedir(), ".microjournal"),
type: "string",
describe: "The path to the journal (defaults to ~/.microjournal"
})
.command("create <message>", "creates a new journal entry", yargs => yargs
.positional("message", {
alias: "m",
......@@ -23,10 +28,13 @@ Yargs
})
.demandOption(["message"])
, (argv: { [key: string]: any }) => {
const accessor = new FolderAccessor(argv.path);
const store = new DataStore(accessor);
const message: string = argv.message
const journal: string = argv.journal
if (message && journal) {
foo.accessor
store.accessor
.create(journal, {
date: new Date(),
data: {
......@@ -41,8 +49,11 @@ Yargs
});
}
})
.command("journals", "lists journals", yargs => yargs, () => {
foo.accessor.listJournals()
.command("journals", "lists journals", yargs => yargs, (argv: { [key: string]: any }) => {
const accessor = new FolderAccessor(argv.path);
const store = new DataStore(accessor);
store.accessor.listJournals()
.subscribe({
next: j => {
console.log("" + j.slug)
......@@ -56,9 +67,12 @@ Yargs
describe: "The name of the journal (defaults to \"default\")"
})
, (argv: any) => {
const accessor = new FolderAccessor(argv.path);
const store = new DataStore(accessor);
const journal: string = argv.journal
if (journal) {
foo.accessor.list(journal)
store.accessor.list(journal)
.subscribe({
next: entry => {
if (entry.date) {
......
......@@ -27,6 +27,6 @@
"yargs": "^12.0.5"
},
"bin": {
"mj": "build/index.ts"
"mj": "build/index.js"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment