Commit 81c4296c authored by Michael Kyriakou's avatar Michael Kyriakou
Browse files

Improved CLI and README.

parent 1424591f
Pipeline #209699 passed with stage
in 58 seconds
......@@ -193,27 +193,29 @@ If you haven't already configured a "second_db", you will need to configure one
## Tutorial: Inserting Rows
You can insert rows using raw SQL queries via PgAdmin, however you can also insert rows using the CLI.
1. Navigate to "cli_handler.py", let's see what commands are available to us.
1. Lets make a mistake, run: `app.py bad cli call`.
2. CTRL + F: CLI Argument Names
2. Navigate to "cli_handler.py", let's see what commands are available to us.
3. This region contains all arguments you are allowed to specify, for example: `app.py action=insert-iris-class binding=second_db ...`.
3. CTRL + F: CLI Argument Names
4. The valid "binding" values are those associated with your databases, it'll allow the CLI to determine which db to operate on.
4. This region contains all arguments you are allowed to specify, for example: `app.py action=insert-iris-class binding=second_db ...`.
5. Now checkout the available "action" names => CTRL + F: ACTION handlers
5. The valid "binding" values are those associated with your databases, it'll allow the CLI to determine which db to operate on.
6. Lets populate our "IrisClass" table.
6. Now checkout the available "action" names => CTRL + F: ACTION handlers
7. Using the CLI type in: `app.py action=populate-iris-class binding=second_db`. After running this command you should see the table populated in PgAdmin.
7. Lets populate our "IrisClass" table.
8. Lets add a new "Iris Class" to the "IrisClass" table. You can inspect its associated model in: `/models/second_db_models/iris_class.py`. Use the CLI to do this. The new iris class should be called `My Lovel Iris`, and note that to specify strings with space-separation we need to wrap the value in double quotes.
8. Using the CLI type in: `app.py action=populate-iris-class binding=second_db`. After running this command you should see the table populated in PgAdmin.
9. Lets add a new "Iris Class" to the "IrisClass" table. You can inspect its associated model in: `/models/second_db_models/iris_class.py`. Use the CLI to do this. The new iris class should be called `My Lovel Iris`, and note that to specify strings with space-separation we need to wrap the value in double quotes.
`py app.py action=insert-iris-class "My Lovely Iris" binding=second_db`
NOTICE: the CLI assumes values not containing '=' are arguments for the "action" handler.
9. Lets add a new "Iris" to the "Iris" table. You can inspect its associated model in: `/models/second_db_models/iris.py`. Use the CLI to do this.
10. Lets add a new "Iris" to the "Iris" table. You can inspect its associated model in: `/models/second_db_models/iris.py`. Use the CLI to do this.
`py app.py action=insert-iris 1.1 2.2 3.3 4.4 "My Lovely Iris" binding=second_db`
......
......@@ -70,6 +70,7 @@ def handle_cli(flask_app, lookup_db_for_binding, args):
selected_action = None
action_args = list()
invalid_cli_call = False
for (i, arg) in enumerate(args):
argname_argvalue_pair = arg.split(NAME_VALUE_SEPARATOR)
pair_len = len(argname_argvalue_pair)
......@@ -89,7 +90,7 @@ def handle_cli(flask_app, lookup_db_for_binding, args):
else:
# Erroneous
invalid_cli_call = True
if invalid_cli_call:
if invalid_cli_call or (len(action_args) > 0 and not selected_action):
print("Invalid CLI call, must be of the format:", CLI_CALL_FORMAT)
exit(-1)
bindings_dict = flask_app.config[APP_CONFIG_BINDINGS_DICT_KEY]
......
Supports Markdown
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