Metadata-Version: 2.4
Name: moat-lib-run
Version: 0.2.0
Summary: Main command entry point infrastructure for MoaT applications
Maintainer-email: Matthias Urlichs <matthias@urlichs.de>
Project-URL: homepage, https://m-o-a-t.org
Project-URL: repository, https://github.com/M-o-a-T/moat
Keywords: MoaT
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AnyIO
Classifier: Framework :: Trio
Classifier: Framework :: AsyncIO
Classifier: Programming Language :: Python :: 3
Classifier: Intended Audience :: Developers
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: anyio~=4.0
Requires-Dist: moat-util~=0.63.0
Requires-Dist: asyncclick~=8.3
Requires-Dist: simpleeval~=1.0
Requires-Dist: moat-lib-config~=0.2.0
Requires-Dist: moat-lib-proxy~=0.1.1
Dynamic: license-file

# moat-lib-run

% start main
% start synopsis

Main command entry point infrastructure for MoaT applications.

% end synopsis

This module provides the infrastructure for building command-line interfaces
for MoaT applications. It includes:

- Command-line argument parsing with Click integration
- Subcommand loading from internal modules and extensions
- Configuration file handling
- Logging setup
- Main entry point wrappers for testing

## Usage

### Basic command setup

```python
from moat.lib.run import main_, wrap_main

@main_.command()
async def my_command(ctx):
    """A simple command"""
    print("Hello from my command!")
```

### Loading subcommands

Use `load_subgroup` to create command groups that automatically load subcommands:

```python
from moat.lib.run import load_subgroup
import asyncclick as click

@load_subgroup(prefix="myapp.commands")
@click.pass_context
async def cli(ctx):
    """Main command group"""
    pass
```

### Processing command-line arguments

The `attr_args` decorator and `process_args` function provide flexible
argument handling:

```python
from moat.lib.run import attr_args, process_args

@main_.command()
@attr_args(with_path=True)
async def configure(**kw):
    """Configure the application"""
    config = process_args({}, **kw)
    # config now contains parsed arguments
```

## Key Functions

- `main_`: The default main command handler
- `wrap_main`: Wrapper for the main command, useful for testing
- `load_subgroup`: Decorator to create command groups with automatic subcommand loading
- `attr_args`: Decorator for adding flexible argument handling to commands
- `process_args`: Function to process command-line arguments into configuration
- `Loader`: Click group class that loads commands from submodules and extensions

% end main
