Skip to content

Commit

Permalink
added a sandbox file for fleshing out re-do of App.run to use Bastion…
Browse files Browse the repository at this point in the history
….Idiomatic methods
  • Loading branch information
ndenny committed Jun 10, 2025
1 parent 98a8391 commit f6d1ee4
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions lab/jogmod.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f6d1ee4

Please sign in to comment.