diff --git a/README.md b/README.md
index 8bd841e..b21a44f 100644
--- a/README.md
+++ b/README.md
@@ -88,6 +88,60 @@ $ source script/basic.sh
3. The return value is as follows:
> Bye, There
+### How to initialize the locally installed templates
+* All of the templates are located in the **templates** directory.
+* Initially, you will need to create the location of the main working directory.
+* The working directory will store all of the available templates.
+* Simply, execute the following command in the command-line interface to setup.
+
+``` sh
+./setup.sh --action=init
+```
+
+* The previous command will create the default templates.
+* List these templates via the following command:
+``` sh
+./py2shell --templates
+```
+* Results are as follows:
+
+
+==== Available Templates: ====
+1: advanced::shifting_args_extended - An extended example of using the shift command to pass parameters.
+2: advanced::shifting_args - An example of using the shift command to pass parameters.
+3: default::template_data - A template to test build a generic script.
+4: standard::standard - Standard script with help menu, conditions and conditional loops.
+5: basic::basic - A basic BASH shell script.
+6: basic::math - Random Math Applications
+7: animators::animation - Create a flipping animation
+8: data::data_cleaner_revised - A BASH revised shell script to clean up a Big Data dataset and save to clean_data.
+9: data::data_cleaner - A BASH shell script to clean up a Big Data dataset and save to clean_data.
+
+
+* All of the templates are then stored in the home directory as the name **~/.py2shell/templates**.
+
+### How to update the locally installed templates after modifying
+* After you add or modify a template located in the **templates** directory.
+* Simply, execute the following command in the command-line interface to update and push to the **~/.py2shell/templates** directory.
+
+``` sh
+./setup.sh --action=update
+```
+* Returns the following output:
+
+
+Pushing, 6 templates
+'templates/basic/math.json' -> '/home/denezt/.py2shell/templates/basic/math.json'
+'templates/basic/basic.json' -> '/home/denezt/.py2shell/templates/basic/basic.json'
+'templates/advanced/shifting_args.json' -> '/home/denezt/.py2shell/templates/advanced/shifting_args.json'
+'templates/advanced/shifting_args_extended.json' -> '/home/denezt/.py2shell/templates/advanced/shifting_args_extended.json'
+'templates/animators/animation.json' -> '/home/denezt/.py2shell/templates/animators/animation.json'
+'templates/default/template_data.json' -> '/home/denezt/.py2shell/templates/default/template_data.json'
+'templates/standard/standard.json' -> '/home/denezt/.py2shell/templates/standard/standard.json'
+'templates/data/data_cleaner_revised.json' -> '/home/denezt/.py2shell/templates/data/data_cleaner_revised.json'
+'templates/data/data_cleaner.json' -> '/home/denezt/.py2shell/templates/data/data_cleaner.json'
+
+
### Contributors:
diff --git a/auto_shell_scripting/TemplateBuilder.py b/auto_shell_scripting/TemplateBuilder.py
index 949da1d..9def366 100755
--- a/auto_shell_scripting/TemplateBuilder.py
+++ b/auto_shell_scripting/TemplateBuilder.py
@@ -14,7 +14,7 @@ class TemplateBuilder:
def buildIfStatement(self, if_statement: dict) -> str:
statement_builder = ""
- print("Building, if statement")
+ print("\033[35mBuilding, if statement\033[0m")
if_statements = ""
goal = ""
for key, value in if_statement:
@@ -26,12 +26,12 @@ def buildIfStatement(self, if_statement: dict) -> str:
if if_statements:
statement_builder += "\n"
statement_builder += "if [ {} ]; then\n".format(goal)
- statement_builder += if_statements
+ statement_builder += "{}".format(if_statements)
statement_builder += "fi\n"
- return statement_builder
-
+ return statement_builder
+
def buildCaseStatement(self, case_statement: dict) -> str:
- print("Building, case statement")
+ print("\033[35mBuilding, case statement\033[0m")
switch_array = ""
statement_builder = ""
goal = ""
@@ -48,8 +48,26 @@ def buildCaseStatement(self, case_statement: dict) -> str:
statement_builder += "esac\n"
return statement_builder
+ def buildNestedIfStatement(self, if_statement: dict) -> str:
+ statement_builder = ""
+ print("\033[35mBuilding, nested if statement\033[0m")
+ if_statements = ""
+ goal = ""
+ for key, value in if_statement:
+ if key == "goal":
+ goal = value
+ if key == "run":
+ for k in value:
+ if_statements += "\t{}".format(self.iterateRun(k))
+ if if_statements:
+ statement_builder += "\n"
+ statement_builder += "\tif [ {} ]; then\n".format(goal)
+ statement_builder += "\t{}".format(if_statements)
+ statement_builder += "\tfi\n"
+ return statement_builder
+
def buildNestedCaseStatement(self, case_statement: dict) -> str:
- print("Building, case statement")
+ print("\033[35mBuilding, nested case statement\033[0m")
switch_array = ""
statement_builder = ""
goal = ""
@@ -67,7 +85,7 @@ def buildNestedCaseStatement(self, case_statement: dict) -> str:
return statement_builder
def buildForStatement(self, loop_statement: dict) -> str:
- print("Building, loop statement")
+ print("\033[35mBuilding, loop statement\033[0m")
statement_builder = ""
for_statements = ""
goal = ""
@@ -84,7 +102,7 @@ def buildForStatement(self, loop_statement: dict) -> str:
return statement_builder
def buildWhileStatement(self, loop_statement: dict) -> str:
- print("Building, loop statement")
+ print("\033[35mBuilding, loop statement\033[0m")
statement_builder = ""
while_statements = ""
goal = ""
@@ -114,6 +132,8 @@ def getConditionBuilder(self, value) -> str:
template += self.buildIfStatement(arr.items())
elif condition_type == "case":
template += self.buildCaseStatement(arr.items())
+ elif condition_type == "if.nested":
+ template += self.buildNestedIfStatement(arr.items())
elif condition_type == "case.nested":
template += self.buildNestedCaseStatement(arr.items())
elif condition_type == "for":
@@ -123,7 +143,7 @@ def getConditionBuilder(self, value) -> str:
return template
def buildFunction(self, function: dict) -> str:
- print("Building, function statement")
+ print("\033[35mBuilding, function statement\033[0m")
statement_builder = ""
statements = ""
name = ""
@@ -133,16 +153,16 @@ def buildFunction(self, function: dict) -> str:
if key == "statements":
for stmt in value:
if stmt.keys().__contains__('conditions'):
- condition = [v for k, v in stmt.items()][0]
+ condition = [ v for k, v in stmt.items()][0]
statements += self.getConditionBuilder(condition)
else:
- print(f"Build Function [stmt]: {stmt}")
+ print(f"\033[35mBuild Function [stmt]:\033[32m {stmt}\033[0m")
statements += "\t" + self.iterateRun(stmt)
if key in [ "control", "oneliner" ]:
statements += "\t" + self.buildOneliner(value)
if statements:
statement_builder += "{}(){}".format(name, '{\n')
- statement_builder += statements
+ statement_builder += "{}".format(statements)
statement_builder += "}\n"
return statement_builder
@@ -165,14 +185,14 @@ def buildOneliner(self, value: dict) -> str:
line = ""
key = list(value.keys())
values = list(value.values())
- print(f"Build Oneliner [key0, values]: {key}, {values}")
+ print(f"\033[35mBuild Oneliner [key0, values]: \033[32m{key}, {values}\033[0m")
for v in values[0]:
line += self.replaceMetaTag(v)
return "{} {}\n".format(key[0], line)
# Normal nested inside of a conditional statement, function and loops
def iterateRun(self, template_data: dict) -> str:
- print(f"Template Data [iterateRun]: {type(template_data)} => {template_data}")
+ print(f"\033[35mTemplate Data [iterateRun]: \033[33m{type(template_data)} \033[35m=> \033[32m{template_data}\033[0m")
line_statement = ""
run_type = ""
try:
@@ -192,8 +212,8 @@ def iterateRun(self, template_data: dict) -> str:
elif key == "function_call":
line_statement += value + "\n"
except AttributeError as ae:
- print("Check datasource syntax and ensure you are using the correct datatype (array, object)")
- print(ae)
+ print("\033[35mCheck datasource syntax and ensure you are using the correct datatype (array, object)\033[0m")
+ print("\033[31m{}\033[0m".format(ae))
exit(1)
return line_statement
@@ -211,7 +231,7 @@ def getTemplateData(self, templates, datasource: str) -> dict:
datasource))
except Exception as e:
print(
- "Error: Missing or unable to find template (name: {})".format(datasource))
+ "\033[35mError: \033[31mMissing or unable to find template (name: {})\033[0m".format(datasource))
return template_data
def generate_template(self, template_data: dict) -> str:
@@ -221,7 +241,7 @@ def generate_template(self, template_data: dict) -> str:
print("\033[36mPURPOSE: \033[33m{}\033[0m".format(value))
# Writes the initial shell
if key in ["shell.type"]:
- print("Shell Type is {}".format(value))
+ print("\033[36mShell Type is \033[36m{}\033[0m".format(value))
template += "#!/usr/bin/env {}\n\n".format(value)
# template += "set -x\n\n"
elif key in ["define.variables"]:
diff --git a/changelog.md b/changelog.md
index 3970753..1fb6a84 100644
--- a/changelog.md
+++ b/changelog.md
@@ -16,6 +16,24 @@ All notable changes to this project will be documented in this file.
### Removed
-
-->
+
+## [2.2.0] - 2024-05-02
+
+### Added
+- Adding the nested if condition for function, which will add an indentation for better formatting.
+
+### Changed
+- Updated template builder with a nested if statement for functions.
+- Modified the setup script with a new resynchronization function to update templates.
+
+## [2.0.0] - 2024-05-02
+
+### Added
+- Add more templates and fix older templates to make command call objects use an array
+
+### Changed
+- Updated template builder and template lister class.
+
## [1.0.2] - 2024-03-18
### Added
@@ -27,7 +45,6 @@ All notable changes to this project will be documented in this file.
- All templates require the `name`, `purpose`, and `category` key.
- Setup script will create a __.py2shell__ file in the home drive.
-
## [1.0.1] - 2023-04-12
### Added
@@ -50,6 +67,8 @@ All notable changes to this project will be documented in this file.
- Initial Commit
+[2.2.0]: https://github.com/denezt/automate-shell-scripting/compare/v2.0.0...v2.2.0
+[2.0.0]: https://github.com/denezt/automate-shell-scripting/compare/v1.0.2...v2.0.0
[1.0.2]: https://github.com/denezt/automate-shell-scripting/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/denezt/automate-shell-scripting/compare/v1.0.0...v1.0.1
[1.0.0]: https://github.com/denezt/automate-shell-scripting/releases/tag/v1.0.0
\ No newline at end of file
diff --git a/img/logo.png b/img/logo.png
index 1282a20..c39d0b2 100644
Binary files a/img/logo.png and b/img/logo.png differ
diff --git a/setup.sh b/setup.sh
index c556823..d0e60bc 100755
--- a/setup.sh
+++ b/setup.sh
@@ -42,6 +42,21 @@ initialize() {
printf "\033[32mInitialization process is complete!!!\033[0m\n"
}
+resync_templates(){
+ userpath="${HOME}/.py2shell"
+ if [ ! -d "${userpath}" ];
+ then
+ mkdir -vp "${userpath}"
+ fi
+ if [ -d "${template_dir}" ];
+ then
+ printf "\033[1;36mPushing, $(ls ${template_dir} | wc -l) templates\033[0m\n"
+ cp -a -v "${template_dir}" "${userpath}"
+ else
+ error "Missing or unable to locate templates directory"
+ fi
+}
+
usage() {
printf "\033[36mUSAGE:\033[0m\n"
printf "\033[35m$0 \033[33m--action=\033[32mCOMMAND\033[0m\n"
@@ -50,7 +65,8 @@ usage() {
commands() {
printf "\033[36mCOMMANDS:\033[0m\n"
- printf "\033[35mInitial Install \033[32m[ init, initialize, setup, install ]\033[0m\n"
+ printf "\033[35mInitial Install\t\t\033[32m[ init, initialize, setup, install ]\033[0m\n"
+ printf "\033[35mUpdate Templates\t\033[32m[ push, resync, update ]\033[0m\n"
printf "\n"
}
@@ -72,4 +88,5 @@ done
case $_action in
init|initialize|setup|install) initialize;;
+ push|resync|update) resync_templates;;
esac
diff --git a/templates/data/data-cleaner.json b/templates/data/data_cleaner_revised.json
similarity index 88%
rename from templates/data/data-cleaner.json
rename to templates/data/data_cleaner_revised.json
index 8610b7d..1809fd6 100755
--- a/templates/data/data-cleaner.json
+++ b/templates/data/data_cleaner_revised.json
@@ -1,6 +1,6 @@
{
- "name": "data_cleaner",
- "purpose": "A BASH shell script to clean up a Big Data dataset and save to clean_data.",
+ "name": "data_cleaner_revised",
+ "purpose": "A BASH revised shell script to clean up a Big Data dataset and save to clean_data.",
"category": "data",
"shell.type": "bash",
"define.variables": {
diff --git a/templates/standard/standard.json b/templates/standard/standard.json
index 8c7881d..b288261 100755
--- a/templates/standard/standard.json
+++ b/templates/standard/standard.json
@@ -18,7 +18,7 @@
{
"conditions": [
{
- "type": "if",
+ "type": "if.nested",
"goal": "1 -gt 1",
"run": [
{
@@ -40,7 +40,7 @@
{
"conditions": [
{
- "type": "if",
+ "type": "if.nested",
"goal": "1 == 1",
"run": [
{
@@ -72,7 +72,7 @@
"type": "if",
"goal": "1 == 1",
"run": [
- {
+ {
"command_call": {
"printf": [
"__BEGIN__",
@@ -101,7 +101,7 @@
"run": [
{
"command_call": {
- "printf": [
+ "printf": [
"__BEGIN__",
"loop...",
"__NEWLINE__",
@@ -140,4 +140,4 @@
]
}
]
-}
\ No newline at end of file
+}