From 3e3f924a9df6b57b39e627dc379c8d2015a14502 Mon Sep 17 00:00:00 2001 From: Ken Date: Thu, 10 Aug 2017 07:00:05 +0800 Subject: [PATCH] #42 - CLI helper / personal assistant on command prompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit for php helper and linux/macos shell runner, outstanding is windows batch file. The TagUI scripts are already in natural-language-like syntax to convert to JS code. I want to have a helper that can convert natural-language-like instructions on the command line to call the right scripts with right parameters. Instead of typing tagui download_bank_report june on command prompt, I think it is more intuitive to support typing erina download my june bank report or something like that directly on command prompt. And let the magic happens behind the scenes to return the results. running this - erina 5w1h/verb fillers options/modifiers fillers single-or-multi-word-context results in running - tagui 5w1h/verb_context quiet options/modifiers calling using chrome/firefox/headless or with chrome/firefox/headless at the end of erina … will call tagui in visible chrome, firefox, headless chrome respectively. this feature allows future extension to natural language voice control. the trigger word erina can be changed by just renaming the erina file (macos/linux) or erina.cmd (windows) file. --- .gitignore | 4 +++ package.json | 2 +- src/erina | 23 ++++++++++++++ src/tagui | 4 +-- src/tagui.cmd | 2 +- src/tagui_helper.php | 75 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 106 insertions(+), 4 deletions(-) create mode 100755 src/erina create mode 100644 src/tagui_helper.php diff --git a/.gitignore b/.gitignore index 1bc88bc4..702bca3a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ /src/samples/8_hastebin.js /src/samples/8_hastebin.log +# exclude generated files for cli assistant +/src/tagui_helper +/src/tagui_helper.cmd + # exclude local log files from api service /src/tagui_service.in /src/tagui_service.out diff --git a/package.json b/package.json index 2efe0cf6..00882e60 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tagui", - "version": "2.2.0", + "version": "2.3.0", "description": "General purpose tool for automating web interactions", "keywords": [ "tagui" diff --git a/src/erina b/src/erina new file mode 100755 index 00000000..b9856e50 --- /dev/null +++ b/src/erina @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# HELPER ASSISTANT SCRIPT FOR RUNNING TAGUI FRAMEWORK ~ TEBEL.ORG # + +# save location of initial directory where helper is called +initial_dir=`pwd` + +# change current directory to TAGUI directory +SOURCE="${BASH_SOURCE[0]}" # slimerjs's implementation instead of cd "`dirname "$0"`" +while [ -h "$SOURCE" ]; do TAGUI_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" +SOURCE="$(readlink "$SOURCE")"; [[ $SOURCE != /* ]] && SOURCE="$TAGUI_DIR/$SOURCE"; done +TAGUI_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"; cd "$TAGUI_DIR" + +# delete helper file if it exists to prevent running an old call +if [ -f "tagui_helper" ]; then rm tagui_helper; fi + +# call php helper to interpret parameters passed in to cli helper +php -q tagui_helper.php $1 $2 $3 $4 $5 $6 $7 $8 $9 + +# run generated output from php helper to call automation flow +if [ -f "tagui_helper" ]; then ./tagui_helper; fi + +# change back to initial directory where tagui is called +cd "$initial_dir" diff --git a/src/tagui b/src/tagui index cc5ce5cb..0f330d93 100755 --- a/src/tagui +++ b/src/tagui @@ -6,7 +6,7 @@ chrome_command="google-chrome" if [ -z "$1" ] then -echo "tagui v2.2: use following syntax and below options to run ./tagui flow_filename option(s)" +echo "tagui v2.3: use following syntax and below options to run ./tagui flow_filename option(s)" echo echo "IMPORTANT: SAVE YOUR WORK BEFORE USING CHROME OR HEADLESS, TAGUI WILL RESTART CHROME" echo "headless - run on invisible Chrome web browser instead of default PhantomJS (first install Chrome)" @@ -185,7 +185,7 @@ if [ -f "tagui.sikuli/tagui_sikuli.in" ]; then rm tagui.sikuli/tagui_sikuli.in; if [ -f "tagui.sikuli/tagui_sikuli.out" ]; then rm tagui.sikuli/tagui_sikuli.out; fi # delete chrome / headless chrome integration files if they exist -if [ -f "tagui_chrome.in" ]; then rm tagui_chrome.in; fi; +if [ -f "tagui_chrome.in" ]; then rm tagui_chrome.in; fi if [ -f "tagui_chrome.out" ]; then rm tagui_chrome.out; fi # default exit code 0 to mean no error parsing automation flow file diff --git a/src/tagui.cmd b/src/tagui.cmd index 58beb9b1..1cede93f 100644 --- a/src/tagui.cmd +++ b/src/tagui.cmd @@ -8,7 +8,7 @@ rem enable windows for loop advanced flow control setlocal enableextensions enabledelayedexpansion if "%~1"=="" ( -echo tagui v2.2: use following syntax and below options to run - tagui flow_filename option^(s^) +echo tagui v2.3: use following syntax and below options to run - tagui flow_filename option^(s^) echo. echo IMPORTANT: SAVE YOUR WORK BEFORE USING CHROME OR HEADLESS, TAGUI WILL RESTART CHROME echo headless - run on invisible Chrome web browser instead of default PhantomJS ^(first install Chrome^) diff --git a/src/tagui_helper.php b/src/tagui_helper.php new file mode 100644 index 00000000..21171a86 --- /dev/null +++ b/src/tagui_helper.php @@ -0,0 +1,75 @@ +