Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
command line options
#1
the arguments can include AWS region names or their abbreviations. each name needs to be verified against the official list. the official list is obtained from an AWS region. by default the region is the primary one. but an option exists to specify which region to get the list from. that option could be specified after the regions given in the arguments. so processing could be out of order. command line parsing is fun. and have to find a library that can handle all my needs. the is just one example.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Plubum.cli should work
from plumbum import cli


class App(cli.Application):
    _choice = None
    
    @cli.switch("-c", str)
    def choose(self, choice):
        self._choice=choice
    
    def main(self, *regions):
        print(regions)
        print(self._choice)
        
if __name__ == '__main__':
    App().run()
Output:
~/P/S/2020-01 python3 paillasse/commandfun.py foo bar spam eggs -c baz ('foo', 'bar', 'spam', 'eggs') baz
Reply
#3
i also need to have single letter options combined in one argument. like foo -x -y could be done like foo -xy.

i also need to support options like -f +f --foo ++foo -f=bar +f=bar --foo=bar ++foo=bar and just foo=bar

and even mix them like foo -x -y +a +b == foo -xy+ab
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Why do you need all this? masochism? Have you tried the existing parsers? Please post your attempts.
Reply
#5
i tried 3 different ones about 3 years ago. i could not get to the point of coding with them because their APIs did not offer what i needed. at least the language did.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#6
The combination of foo -f -x and foo -fx works with the ArgumentParser.
If you have so many options, you may better have a default configuration together with a user configuration overloaded.
This can prevent you to enter one million command line options. It's also not practical for the end user.

If I open man ffmepeg I could ????
Then people come into play and program a gui or a helper script to use an unusable command line tool.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  review of command line parsers Skaperen 2 2,059 Mar-11-2021, 07:39 PM
Last Post: Skaperen
  opening python from the command line takes a long time to load? abdulkaderanwar 4 2,986 Jun-22-2020, 03:42 AM
Last Post: abdulkaderanwar
  f-string in command line arguments Skaperen 0 1,574 May-05-2020, 11:49 PM
Last Post: Skaperen
  my own command line option parser Skaperen 0 1,662 Mar-27-2020, 04:14 AM
Last Post: Skaperen
  i need a module for more involved command line parsing Skaperen 21 7,112 Sep-04-2019, 02:18 AM
Last Post: Skaperen
  is there an options parser that can handle + and ++ Skaperen 1 1,565 Jul-20-2019, 07:42 PM
Last Post: metulburr
  variable args + named options Skaperen 0 1,864 Aug-15-2018, 11:14 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020