Skip to main content
Introduction
============
Skal is a wrapper for the argparser library to make it easier to write
applications that uses commands with subcommands, much like git and
heroku does.

Skal can be used with different combinations of command sources; a subclass of
SkalApp, any number of modules and any number of packages. Currently usage with
classes and modules are supported.

The test cases are a good source of different ways to use Skal appart
from what is described here.

Subclass as command source
==========================
A custom subclass of SkalApp is one way to get some commands added, and
may be the shortest version.

In file myapp.py:
```python
from skal import SkalApp, command

class MyApp(SkalApp):
@command
def hello(self):
print('hello')

@command
def yes(self):
print('yes')

if __name__ == '__main__':
MyApp().run()
```

Running the program:
```
> python myapp.py hello
hello

> python myapp.py yes
yes
```

Modules as command source
=========================
There are two ways in which modules can be used to source commands;
either as a flat hirearchy where every function in every module gets
added or with a bit of hirearchy where each module becomes a command and
its functions becomes subcommands. Using either is determined by how the
module names are passed to the SkalApp constructor, and any combination
is also valid. The only advice is to specify a overridden version and
description string for the whole app, as Skal wouldn't otherwise know
where to get that information from. When using only modules there is no
need to override the SkalApp class.

First a module called do.py:
```python
from skal import command

@command
def hello(self):
print('hello')

@command
def yes(self):
print('yes')
```

Using do.py as plain commands in myapp.py:
```
from skal import SkalApp

if __name__ == '__main__':
SkalApp(command_modules = ['do']).run()
```

Running the program:
```
> python myapp.py hello
hello

> python myapp.py yes
yes
```

Using do.py as a subcommand in myapp.py:
```
from skal import SkalApp

if __name__ == '__main__':
SkalApp(subcommand_modules = ['do']).run()
```

Running the program:
```
> python myapp.py do hello
hello

> python myapp.py do yes
yes
```

Per Command Arguments
======================
This shows the usage of custom arguments per command. This works for all
supported command sources, not only classes.
```python
from skal import SkalApp, command, default

class MyApp(SkalApp):
"""Help line for application"""

__args__ = {
'-a': {'help': 'Help for a', 'action': 'store_true'},
'-b': {'help': 'Help for b', 'action': 'store_true'}
}

@command({
('-d', '--delete'): {'help': 'Help for d', 'action': 'store_true'}
})
def hello(self):
"""Help line for hello"""
if self.args.a:
print('a')
if self.args.b:
print('b')
if self.args.delete:
print('deleting')
print('hello')

@command
def yes(self):
"""Help line for yes"""
if self.args.a:
print('a')
if self.args.b:
print('b')
print('yes')

if __name__ == '__main__':
app = MyApp()
sys.exit(app.run())
```

Running it:
```
> python myapp.py -a hello --delete
a
deleting
hello

> python myapp.py -b yes
b
yes
```

License
=======
Skal is licensed under Apache License 2.0

http://www.apache.org/licenses/LICENSE-2.0

Release files for skal 0.1.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for skal 0.1.13
File Size Uploaded
skal-0.1.13.tar.gz 9.6 kB Details

Release files / skal-0.1.13.tar.gz

Download URL skal-0.1.13.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b938a9a910aee5957bf8b23c5efc88d81115dff4b2b123dccf27bffb123cc7ee
BLAKE2b-256 checksum
How to use checksums
e66d71e7cf41629f5aa20f3f09398f6d63743749250e23b7243dc994283bd47a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.13 This release

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page