trustcrypto / python-onlykey

The OnlyKey Python Command-Line Utility is a command line tool targeted towards more advanced users. This can be used for configuration and testing.
https://docs.crp.to/command-line.html
47 stars 22 forks source link

added help section, refactor with argparse #41

Open ranfdev opened 3 years ago

ranfdev commented 3 years ago

As said in issue #40, I've rewritten the client to use argparse, so that the users can have a better user experience.

I haven't tested every function, so there may be many bugs. Examples now:

❯ python -m onlykey -h
usage: __main__.py [-h]
                   {version,fwversion,help,getlabels,getkeylabels,setslot,wipeslot,wipekey,idletimeout,keylayout,wipemode,keytypespeed,ledbrightness,storedkeymode,derivedkeymode,backupkeymode,2ndprofilemode,sysadminmode,lockbutton,hmackeymode,rng,ping,wink,setkey,init,credential}
                   ...

optional arguments:
  -h, --help            show this help message and exit

commands:
  {version,fwversion,help,getlabels,getkeylabels,setslot,wipeslot,wipekey,idletimeout,keylayout,wipemode,keytypespeed,ledbrightness,storedkeymode,derivedkeymode,backupkeymode,2ndprofilemode,sysadminmode,lockbutton,hmackeymode,rng,ping,wink,setkey,init,credential}
    version             display the version of the app
    fwversion           display the version of the OnlyKey firmware
    help                this message
    getlabels           return slot's labels
    getkeylabels        show key's labels
    setslot             set slot action, label ...
    wipeslot            wipe slot
    wipekey             wipe key
    idletimeout         OnlyKey locks after idletimeout is reached
    keylayout           set keyboard layout
    idletimeout         set idletimeout
    wipemode            set wipemode
    keytypespeed        set keytypespeed
    ledbrightness       set ledbrightness
    storedkeymode       set storedkeymode
    derivedkeymode      set derivedkeymode
    backupkeymode       set backupkeymode
    2ndprofilemode      set 2ndprofilemode
    sysadminmode        set sysadminmode
    lockbutton          set lockbutton
    hmackeymode         set hmackeymode
    rng                 generate rng content
    ping                send ping
    wink                send wink command to key (blinks LED a few times).
    setkey              set key in a slot
    init                setup onlykey
    credential          credential actions
❯ python -m onlykey setslot -h
usage: __main__.py setslot [-h] id {label,ecckeylabel,rsakeylabel,url,addchar1,delay1,username,addchar2,delay2,password,addchar3,delay3,2fa,totpkey,addchar4,addchar5} value

positional arguments:
  id
  {label,ecckeylabel,rsakeylabel,url,addchar1,delay1,username,addchar2,delay2,password,addchar3,delay3,2fa,totpkey,addchar4,addchar5}
  value

optional arguments:
  -h, --help            show this help message and exit
❯ python -m onlykey keylayout --list-all
1 USA_ENGLISH (Default)
2 CANADIAN_FRENCH
3 CANADIAN_MULTILINGUAL
4 DANISH
5 FINNISH
6 FRENCH
7 FRENCH_BELGIAN
8 FRENCH_SWISS
9 GERMAN
10 GERMAN_MAC
11 GERMAN_SWISS
12 ICELANDIC
13 IRISH
14 ITALIAN
15 NORWEGIAN
16 PORTUGUESE
17 PORTUGUESE_BRAZILIAN
18 SPANISH
19 SPANISH_LATIN_AMERICA
20 SWEDISH
21 TURKISH
22 UNITED_KINGDOM
23 US_INTERNATIONAL
24 CZECH
25 SERBIAN_LATIN_ONLY
26 HUNGARIAN
27 DANISH MAC
28 US_DVORAK

I have added a __main__.py file to help me test things more quickly from the shell. Most of the commands should work as before. Even the interactive shell is still there. I'm going to leave this here, in the hope somebody reviews the code and test it.