timcowlishaw / xic

Tiny tools for thick description
0 stars 0 forks source link

Xic: Single-script metaprogramming (terrible idea), CLI interactions #5

Open jcalpickard opened 2 months ago

jcalpickard commented 2 months ago

While trying to bend my head around sys.argv, stumbled across some interesting affordances for metaprogramming and polymorphism. We could, it turns out, unify Xic's "tiny tools for thick description" (Jotter, Prompter, etc.) into a single Python script that behaves differently based on how it's invoked. This approach leverages sys.argv for metaprogramming, potentially simplifying maintenance and distribution while retaining the distinct functionality of each tool.

Proposal: Leverage sys.argv for metaprogramming to create a single Python script that functions as multiple tools based on how it's invoked. This could simplify maintenance and distribution while preserving the distinct functionality of each tool.

Implementation: Create a single Python script containing functions for each tool (jotter(), prompter(), parser()). Use sys.argv to check the script's filename and determine which function to execute. Create symbolic links or copies with different names (jotter.py, prompter.py, parser.py) that all point to the main script.

jcalpickard commented 2 months ago

Counter-proposal from @timcowlishaw:

argparse

As part of this, it'd be possible to set up shell aliases (e.g., alias jot='python xic.py jotter') to further reduce friction when calling (invoking?) specific Xic tools.

We'd need to consider how the alias (or alternative short command, e.g., 'xic jot') integrates into typical development workflows. How easily can a developer switch from coding to jotting and back?