Coder Social home page Coder Social logo

foobar's Introduction

build status coverage

Foobar

An example package. See full documentation.

Installation

  1. Clone the repository and enter it:

    $ git clone [email protected]:dan-gittik/foobar.git
    ...
    $ cd foobar/
  2. Run the installation script and activate the virtual environment:

    $ ./scripts/install.sh
    ...
    $ source .env/bin/activate
    [foobar] $ # you're good to go!
  3. To check that everything is working as expected, run the tests:

    $ pytest tests/
    ...

Usage

The foobar packages provides the following classes:

  • Foo

    This class encapsulates the concept of foo, and returns "foo" when run.

    In addition, it provides the inc method to increment integers, and the add method to sum them.

    >>> from foobar import Foo
    >>> foo = Foo()
    >>> foo.run()
    'foo'
    >>> foo.inc(1)
    2
    >>> foo.add(1, 2)
    3
  • Bar

    This class encapsulates the concept of bar; it's very similar to Foo, except it returns "bar" when run.

    >>> from foobar import Bar
    >>> bar = Bar()
    >>> bar.run()
    'bar'

The foobar package also provides a command-line interface:

$ python -m foobar
foobar, version 0.1.0

All commands accept the -q or --quiet flag to suppress output, and the -t or --traceback flag to show the full traceback when an exception is raised (by default, only the error message is printed, and the program exits with a non-zero code).

The CLI provides the foo command, with the run, add and inc subcommands:

$ python -m foobar foo run
foo
$ python -m foobar foo inc 1
2
$ python -m foobar foo add 1 2
3

The CLI further provides the bar command, with the run and error subcommands.

Curiously enough, bar's run subcommand accepts the -o or --output option to write its output to a file rather than the standard output, and the -u or --uppercase option to do so in uppercase letters.

$ python -m foobar bar run
bar
$ python -m foobar bar run -u
BAR
$ python -m foobar bar run -o output.txt
$ cat output.txt
BAR

Do note that each command's options should be passed to that command, so for example the -q and -t options should be passed to foobar, not foo or bar.

$ python -m foobar bar run -q # this doesn't work
ERROR: no such option: -q
$ python -m foobar -q bar run # this does work

To showcase these options, consider bar's error subcommand, which raises an exception:

$ python -m foobar bar error
ERROR: something went terribly wrong :[
$ python -m foobar -q bar error # suppress output
$ python -m foobar -t bar error # show full traceback
ERROR: something went terribly wrong :[
Traceback (most recent call last):
    ...
RuntimeError: something went terrible wrong :[

foobar's People

Contributors

dan-gittik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.