Commit ccf132f7 authored by Steve Streza's avatar Steve Streza
Browse files

Added search back

parent 7487cab0
Pipeline #701 failed with stage
in 2 minutes and 47 seconds
This diff is collapsed.
......@@ -11,6 +11,8 @@ const createStore = () => {
return store
}
const journalName = () => ((Commander.journal as string) || "personal")
Commander
.version("0.0.1")
.option("-p, --path <path>", "The path to the journal (defaults to ~/.microjournal)")
......@@ -54,71 +56,31 @@ Commander
})
Commander
.command("list [journal]")
.command("list")
.description("lists the contents of the journal")
.action(journal => {
.action(() => {
const store = createStore()
if (journal) {
store.accessor.list(journal)
.subscribe({
next: entry => {
if (entry.date) {
console.log("" + entry.date.toLocaleDateString() + " " + entry.date.toLocaleTimeString() + ": " + entry.data.message)
}
else {
console.log("" + entry.data.message)
}
store.accessor.list(journalName())
.subscribe({
next: entry => {
if (entry.date) {
console.log("" + entry.date.toLocaleDateString() + " " + entry.date.toLocaleTimeString() + ": " + entry.data.message)
}
})
}
})
Commander.parse(process.argv)
/*
.command("list [journal]", "lists the contents of the journal", yargs => yargs
.positional("journal", {
type: "string",
default: "default",
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) {
store.accessor.list(journal)
.subscribe({
next: entry => {
if (entry.date) {
console.log("" + entry.date.toLocaleDateString() + " " + entry.date.toLocaleTimeString() + ": " + entry.data.message)
}
else {
console.log("" + entry.data.message)
}
else {
console.log("" + entry.data.message)
}
})
}
}
})
})
.command("search [journal] [term]", "searches the messages in the journal for a given term", yargs => yargs
.positional("journal", {
type: "string",
default: "default",
describe: "The name of the journal (defaults to \"default\")"
})
.positional("term", {
type: "string",
describe: "The term to search for"
})
, (argv: any) => {
const accessor = new FolderAccessor(argv.path);
const store = new DataStore(accessor);
const term: string = argv.term
const journal: string = argv.journal
if (journal) {
store.accessor.search(term, journal)
Commander
.command("search [term]")
.description("searches the messages in the journal for a given term")
.action((term: string) => {
console.log("Searching: ", term)
if (term) {
const store = createStore()
store.accessor.search(term, journalName())
.subscribe({
next: entry => {
if (entry.date) {
......@@ -131,6 +93,5 @@ Commander.parse(process.argv)
})
}
})
.help()
.argv
*/
\ No newline at end of file
Commander.parse(process.argv)
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