Package: yaargh
Yaargh is a fork of Argh (https://github.com/neithere/argh/).Why fork?The argh project is no longer maintained (https://github.com/neithere/argh/issues/124#issuecomment-383645696).
This project will attempt to fix issues and make improvements to the original project.
The intent is for all these changes to be made back to the original argh project
when that becomes possible, and for yaargh to act as a replacement until it is.You can use yaargh as a drop-in replacement for argh (import yaargh as argh)
though see Compatability below.In order to support using yaargh automatically even in applications where you can’t easily change
the code, the optional featureyaargh[import-argh]will add a dummyarghmodule such thatimport arghwill useyaargh.HighlightsThe most signifigant differences fromargh, and reasons you may prefer to use it:Commands that fail with aCommandErrornow exit with status1(failure) instead of
status0(success). This is extremely important when used in scripts.CompatabilityWhile yaargh strives to maintain backwards compatability with argh and its existing behavior,
the nature of a library likearghwith a large amount of “magic” behavior and defaults
means that what we consider the best default may change from version to version. For example,
help text wording may change.In addition, there is behavior that is almost always a bug but that it is technically possible
some users rely on.Both kinds of compatability breaks are listed below:If a function’s type signature included a*varargsargument with an annotation of
typestr, this annotation previously was ignored. Now, that annotation will be used
as a help string. In almost all cases this should be fixing behavior to match user intent,
but it will technically result in different--helpoutput.Previously, if a function raised ayaargh.CommandErroror an error explicitly marked as wrapped,
thenyaargh.dispatch()(and by extensionyaargh.dispatch_command()andyaargh.dispatch_commands())
would write the error message to the givenerror_file(by defaultsys.stderr), then
return. It now raises a SystemExit instead of returning. In almost all cases,dispatch()is
the last thing the program does anyway, and parsing failures already caused a SystemExit to be
raised so most users who need to do something after error will already be catching it.
This is a signifigant break but is nessecary to allow non-zero exit codes for failed commands.Related to the above, commands that fail with ayaargh.CommandErroror other wrapped error
will now exit with status1, indicating failure. Previously, unless the user did something to avoid it,
the command would have returned fromyaargh.dispatch()and subsequently exited success.
In the vast majority of cases this would have been a latent bug likely to cause havoc in scripts
or other systems which rely on status code to check if a command succeeded.
You can useCommandError(message, code=0)to restore the previous behavior.Original READMEBuilding a command-line interface?  Found yourself uttering “argh!” while
struggling with the API ofargparse?  Don’t like the complexity but need
the power?Everything should be made as simple as possible, but no simpler.—Albert Einstein (probably)Arghis a smart wrapper forargparse.Argparseis a very powerful tool;Arghjust makes it easy to use.In a nutshellArgh-powered applications aresimplebutflexible:Modular:Declaration of commands can be decoupled from assembling and dispatching;Pythonic:Commands are declared naturally, no complex API calls in most cases;Reusable:Commands are plain functions, can be used directly outside of CLI context;Layered:The complexity of code raises with requirements;Transparent:The full power of argparse is available whenever needed;Namespaced:Nested commands are a piece of cake, no messing with subparsers (though
they are of course used under the hood);Term-Friendly:Command output is processed with respect to stream encoding;Unobtrusive:Arghcan dispatch a subset of pure-argparsecode, and pure-argparsecode can update and dispatch a parser assembled withArgh;DRY:The amount of boilerplate code is minimal; among other things,Arghwill:infer command name from function name;infer arguments from function signature;infer argument type from the default value;infer argument action from the default value (for booleans);add an alias root commandhelpfor the--helpargument.NIH free:Arghsupportscompletion,progress barsand everything else by being
friendly to excellent 3rd-party libraries.  No need to reinvent the wheel.Sounds good?  Check the tutorial!Relation to argparseArghis fully compatible withargparse.  You can mixArgh-agnostic andArgh-aware code.  Just keep in mind that the dispatcher does some extra work
that a custom dispatcher may not do.InstallationUsing pip:$ pip install arghArch Linux (AUR):$ yaourt python-arghExamplesA very simple application with one command:importarghdefmain():return'Hello world'argh.dispatch_command(main)Run it:$./app.pyHelloworldA potentially modular application with multiple commands:importargh# declaring:defecho(text):"Returns given word as is."returntextdefgreet(name,greeting='Hello'):"Greets the user with given name. The greeting is customizable."returngreeting+', '+name# assembling:parser=argh.ArghParser()parser.add_commands([echo,greet])# dispatching:if__name__=='__main__':parser.dispatch()Of course it works:$./app.pygreetAndyHello,Andy$./app.pygreetAndy-gArrrghArrrgh,AndyHere’s the auto-generated help for this application (note how the docstrings
are reused):$ ./app.py help

usage: app.py {echo,greet} ...

positional arguments:
    echo        Returns given word as is.
    greet       Greets the user with given name. The greeting is customizable.…and for a specific command (an ordinary function signature is converted
to CLI arguments):$ ./app.py help greet

usage: app.py greet [-g GREETING] name

Greets the user with given name. The greeting is customizable.

positional arguments:
  name

optional arguments:
  -g GREETING, --greeting GREETING   'Hello'(The help messages have been simplified a bit for brevity.)Argheasily maps plain Python functions to CLI.  Sometimes this is not
enough; in these cases the powerful API ofargparseis also available:@arg('text',default='hello world',nargs='+',help='The message')defecho(text):printtextThe approaches can be safely combined even up to this level:# adding help to `foo` which is in the function signature:@arg('foo',help='blah')# these are not in the signature so they go to **kwargs:@arg('baz')@arg('-q','--quux')# the function itself:defcmd(foo,bar=1,*args,**kwargs):yieldfooyieldbaryield', '.join(args)yieldkwargs['baz']yieldkwargs['quux']LinksProject home page(GitHub)Documentation(Read the Docs)Package distribution(PyPI)Questions, requests, bug reports, etc.:Issue tracker(GitHub)Mailing list(subscribe to get important announcements)Direct e-mail (neithere at gmail com)AuthorDeveloped by Andrey Mikhaylenko since 2010.See fileAUTHORSfor a complete list of contributors to this library.SupportThe fastest way to improve this project is to submit tested and documented
patches or detailed bug reports.Otherwise you can “flattr” me:LicensingArgh is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.Argh is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.You should have received a copy of the GNU Lesser General Public License
along with Argh.  If not, see <http://gnu.org/licenses/>.