Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bin/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ else if(flagCheck === undefined){
console.log("run")
options.run();
}
else
options.runCommand(flagCheck);
81 changes: 59 additions & 22 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var cmd = require('node-cmd');

var createJson = () => {
try{
fs.writeFileSync(process.env.HOME+'/.scriptr.json', '{"commandName":[], "commandCode":[]}');
fs.writeFileSync(process.env.HOME||process.env.USERPROFILE+'/.scriptr.json', '{"commandName":[], "commandCode":[]}');
return loadJson();
}
catch(e){
Expand All @@ -14,7 +14,7 @@ var createJson = () => {

var loadJson = () => {
try{
var json = fs.readFileSync(process.env.HOME+'/.scriptr.json');
var json = fs.readFileSync(process.env.HOME||process.env.USERPROFILE+'/.scriptr.json');
return JSON.parse(json);
}
catch(e){
Expand Down Expand Up @@ -57,28 +57,30 @@ var addCommand = () => {

var saveJson = (json) => {
console.log(json);
fs.writeFileSync(process.env.HOME+'/.scriptr.json', JSON.stringify(json));
fs.writeFileSync(process.env.HOME||process.env.USERPROFILE+'/.scriptr.json', JSON.stringify(json));
}

var run = () => {
showMenu();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Select an entry: ', (choice) => {
commands = loadSelection(choice-1);
for(var i = 0; i < commands.length; i++){
// options.checkCd(commands[i]);
cmd.get(
commands[i],
function(err, data, stderr){
console.log(data);
}
);
}
rl.close();
});
if(showMenu())
{
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Select an entry: ', (choice) => {
commands = loadSelection(choice-1);
for(var i = 0; i < commands.length; i++){
// options.checkCd(commands[i]);
cmd.get(
commands[i],
function(err, data, stderr){
console.log(data);
}
);
}
rl.close();
});
}
}

var deleteCommand = () => {
Expand Down Expand Up @@ -116,12 +118,46 @@ var editCommand = () => {

var showMenu = () => {
var scripts = loadJson();
if (scripts.commandName.length == 0)
{
addCommand();
return false;
}
console.log("----------------------------------");
for(var i = 0; i < scripts.commandName.length; i++){
console.log("| "+"("+(i+1)+".) "+scripts.commandName[i]);
}
console.log("----------------------------------");
return true;
}

var runCommand = (cmdname) => {
var scripts = loadJson();
if (scripts.commandName.length == 0)
{
console.log("command "+cmdname+" not found");
return false;
}
console.log("----------------------------------");
for(var i = 0; i < scripts.commandName.length; i++){
if(scripts.commandName[i]==cmdname)
{
commands = loadSelection(i);
for(var j = 0; j < commands.length; j++)
{
cmd.get(
commands[j],
function(err, data, stderr){
console.log(data||err||stderr);
}
);
}
console.log("----------------------------------");
return true;
}
}
console.log("command "+cmdname+" not found");
return false;
}

module.exports = {
Expand All @@ -130,5 +166,6 @@ module.exports = {
loadSelection,
run,
deleteCommand,
editCommand
editCommand,
runCommand
}