Class based command line wrapper
Project description
Introduction
============
Skal is a wrapper for the argparser library to make it easier to write
applications that uses the command-subcommand style, much like git and
heroku.
Basic Usage
===========
Skal can be used on three levels: *class*, *module* and *package*. As this
project is still very young only the class level is implemented as for now.
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__':
app = MyApp()
sys.exit(app.run())
```
Running the small program:
```
> python myapp.py hello
hello
> python myapp.py yes
yes
```
Using Custom Arguments
======================
This shows the usage of custom arguments per subcommand:
*Note that @default decorator is not yet implemented!*
```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')
@default
@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
============
Skal is a wrapper for the argparser library to make it easier to write
applications that uses the command-subcommand style, much like git and
heroku.
Basic Usage
===========
Skal can be used on three levels: *class*, *module* and *package*. As this
project is still very young only the class level is implemented as for now.
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__':
app = MyApp()
sys.exit(app.run())
```
Running the small program:
```
> python myapp.py hello
hello
> python myapp.py yes
yes
```
Using Custom Arguments
======================
This shows the usage of custom arguments per subcommand:
*Note that @default decorator is not yet implemented!*
```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')
@default
@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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
skal-0.1.1.tar.gz
(7.7 kB
view details)
File details
Details for the file skal-0.1.1.tar.gz
.
File metadata
- Download URL: skal-0.1.1.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84bc09a48845f738e607a9e9e0f078d3cef83e40306ba9874b92c1df27d7d84a |
|
MD5 | 52a39a842123ac7ba21eebd1e0b2b5eb |
|
BLAKE2b-256 | 84755498c2d255587894f2dccc9fbd460ad0792b8f56f76de3e54763e78cc993 |