Comments (1)
One approach. Still procedural rather than OO but tidier. Using this approach consistently also allows consistent handling of time and tag strings
prompt user into user_input str
if not user_input:
input_tokens = parse_command( user_input )
cmd = input_tokens[0]
args = input_tokens[1:]
match cmd:
case "edit":
do_edit( args )
etc
def parse_command( user_input: str ):
"""Returns list of command with any arguments as a list ([] if not unrecognized command).
input_tokens = ... split user_input...
# cfg.command_aliases is dict of lists of aliases keyed by canonical command name (e.g. {"edit":["ed","e","edi"], etc})
command = None
for c, aliases in cfg.commands.items():
if input_tokens[0] in aliases:
command = c
break
# any command?
if not command:
return []
# have a recognized command
input_tokens[0] = command
return input_tokens
def do_edit( args:list[str] ):
# Action is identified as 'edit'
tag = get_token( arg[0],optional=False,prompt="Edit what tag?" )
if not (tag := fix_tag( tag, must_be_available=True)):
...error...
return
in_out = get_token( arg[1],optional=False,prompt="Change (i)n or (o)ut time?")
if not (in_out useful):
...error...
return
newtime = get_token( arg[2], optional=False, prompt="Change to what time (blank for now):",default="")
if not (newtime := fix_hhmm(newtime)):
...error...
return
confirm = get_token( arg[3], optional=False,prompt="Change (Y/n):",default="y')
(etc)
from tagtracker.
Related Issues (20)
- enable html colour codes in iprint() styles
- local implementation: cron appears not to start itself in wsl
- dusk does not adjust for DST HOT 1
- Wording tweaks
- easily-fixed flaws in web reports
- remove "replace check-out time with new time" prompt
- -q flag for all database loading scripts HOT 1
- standardize datafile format HOT 1
- web 'audit' report format is different on phones than laptop browser
- Sound file crash on checkout unused tag HOT 1
- commands in uc not recognized
- bits
- assure internet test does not grab cached page
- summary for custom date period HOT 1
- main page web summary: current year
- Improve no-internet detection HOT 1
- Allow different tag labels
- Guess an "in" time for a given tag, when missing
- Checkmark in UR corner when internet is good
- dev bug chasing in #394
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tagtracker.