From f6d1ee4b300ea0af98a11d31ecb83286152a41f2 Mon Sep 17 00:00:00 2001 From: Nathan Denny Date: Tue, 10 Jun 2025 03:41:13 -0400 Subject: [PATCH] added a sandbox file for fleshing out re-do of App.run to use Bastion.Idiomatic methods --- lab/jogmod.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lab/jogmod.py diff --git a/lab/jogmod.py b/lab/jogmod.py new file mode 100644 index 0000000..9db934a --- /dev/null +++ b/lab/jogmod.py @@ -0,0 +1,66 @@ +""" +Some scratch / prototype code for re-implementing the .run() method +to use idioms and intention as a more compact way of building a CLI. +""" +from Bastion.Idiomatic import Idiom, Prompt, Slang + + + def jog(self): + menu = [ + (["list sites provisioned"], self.do_list_sites_provisioned) + (["list sites declared"], self.do_list_sites_declared), + (["perform queued updates"], self.do_perform_queued_updates), + (["become conductor"], self.do_become_conductor), + (["list _ark_ zones declared"], self.do_list_zones_declared), + (["list _ark_ assets declared"], self.do_list_assets_declared), + (["list _ark_ assets protected"], self.do_list_assets_protected), + (["enroll _ark_ assets"], self.do_enroll_assets), + (["queue all assets"], self.do_queue_asset_updates), + (["queue _ark_ updates"], self.do_queue_updates), + (["show _ark_ manifest"], self.do_show_manifest), + (["bank _ark_"], self.do_bank), + (["amend _ark_"], self.do_amend), + (["update _ark_"], self.do_update), + (["restore _ark_"], self.do_restore), + (["help"], self.do_help) + ] + + #-- Look for an explicitly declared session ID in opts; + #-- and fall back to the default if no ID is declared. + opts = { } + self.session = "{}{}".format(Quantim.now().quaver, Boggle(5)) + if 'session.ID' in opts: + self.session = opts['session.ID'] + + prompts = Slang(menu) + chosen = prompts.match( sys.argv[1:], Prompt("help", self.do_help) ) + request = makeRequest(chosen, **opts) + + #-- execute the action within crash guardrails + try: + answer = chosen.action(request) + if not isinstance(answer, isResult): + raise ValueError("actions must respond with an instance of CARP.isReceipt") + except Exception as err: + answer = request.crashed(err) + #-- always log crashes! + answer['log.scope'] = '*' + + #-- check for override on the logging scope. + if "log.scope" in opts: + answer['log.scope'] = opts['log.scope'] + + #-- write the answer to the log, if there is a given log.scope + self.remember(answer) + + #-- write the answer to STDOUT using the current "tongue" (emission format) + self.emit(answer) + + #-- explicitly exit based on the answer to the request + #-- status codes follow the general "theory of reply codes" + #-- e.g. those used in SMTP, HTTP, etc. + if not answer.status.indicates_failure: + sys.exit(0) + else: + sys.exit(1) +