freyja 0.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- freyja-0.0.0/LICENSE +21 -0
- freyja-0.0.0/PKG-INFO +332 -0
- freyja-0.0.0/README.md +309 -0
- freyja-0.0.0/freyja/__init__.py +8 -0
- freyja-0.0.0/freyja/cli/__init__.py +11 -0
- freyja-0.0.0/freyja/cli/class_handler.py +189 -0
- freyja-0.0.0/freyja/cli/enums.py +7 -0
- freyja-0.0.0/freyja/cli/execution_coordinator.py +125 -0
- freyja-0.0.0/freyja/cli/system/__init__.py +16 -0
- freyja-0.0.0/freyja/cli/system/completion.py +155 -0
- freyja-0.0.0/freyja/cli/system/tune_theme.py +644 -0
- freyja-0.0.0/freyja/cli/target_mode.py +3 -0
- freyja-0.0.0/freyja/command/__init__.py +13 -0
- freyja-0.0.0/freyja/command/command_discovery.py +351 -0
- freyja-0.0.0/freyja/command/command_executor.py +188 -0
- freyja-0.0.0/freyja/command/command_info.py +22 -0
- freyja-0.0.0/freyja/command/command_tree.py +233 -0
- freyja-0.0.0/freyja/command/validation.py +144 -0
- freyja-0.0.0/freyja/completion/__init__.py +22 -0
- freyja-0.0.0/freyja/completion/base.py +279 -0
- freyja-0.0.0/freyja/completion/bash.py +125 -0
- freyja-0.0.0/freyja/completion/fish.py +48 -0
- freyja-0.0.0/freyja/completion/installer.py +241 -0
- freyja-0.0.0/freyja/completion/powershell.py +53 -0
- freyja-0.0.0/freyja/completion/zsh.py +50 -0
- freyja-0.0.0/freyja/freyja_cli.py +149 -0
- freyja-0.0.0/freyja/help/__init__.py +9 -0
- freyja-0.0.0/freyja/help/help_formatter.py +722 -0
- freyja-0.0.0/freyja/help/help_formatting_engine.py +241 -0
- freyja-0.0.0/freyja/parser/__init__.py +9 -0
- freyja-0.0.0/freyja/parser/argument_parser.py +163 -0
- freyja-0.0.0/freyja/parser/command_parser.py +288 -0
- freyja-0.0.0/freyja/parser/docstring_parser.py +63 -0
- freyja-0.0.0/freyja/tests/__init__.py +1 -0
- freyja-0.0.0/freyja/tests/conftest.py +77 -0
- freyja-0.0.0/freyja/tests/test_adjust_strategy.py +57 -0
- freyja-0.0.0/freyja/tests/test_ansi_string.py +343 -0
- freyja-0.0.0/freyja/tests/test_cli_class.py +452 -0
- freyja-0.0.0/freyja/tests/test_cli_module.py +286 -0
- freyja-0.0.0/freyja/tests/test_color_adjustment.py +289 -0
- freyja-0.0.0/freyja/tests/test_color_formatter_rgb.py +156 -0
- freyja-0.0.0/freyja/tests/test_command_discovery.py +344 -0
- freyja-0.0.0/freyja/tests/test_completion.py +212 -0
- freyja-0.0.0/freyja/tests/test_comprehensive_module_cli.py +531 -0
- freyja-0.0.0/freyja/tests/test_data_struct_util.py +424 -0
- freyja-0.0.0/freyja/tests/test_examples.py +129 -0
- freyja-0.0.0/freyja/tests/test_hierarchical_command_groups.py +361 -0
- freyja-0.0.0/freyja/tests/test_hierarchical_help_formatter.py +504 -0
- freyja-0.0.0/freyja/tests/test_multi_class_cli.py +283 -0
- freyja-0.0.0/freyja/tests/test_rgb.py +333 -0
- freyja-0.0.0/freyja/tests/test_system.py +326 -0
- freyja-0.0.0/freyja/tests/test_text_util.py +383 -0
- freyja-0.0.0/freyja/tests/test_theme_color_adjustment.py +280 -0
- freyja-0.0.0/freyja/theme/__init__.py +28 -0
- freyja-0.0.0/freyja/theme/color_formatter.py +114 -0
- freyja-0.0.0/freyja/theme/enums.py +92 -0
- freyja-0.0.0/freyja/theme/rgb.py +355 -0
- freyja-0.0.0/freyja/theme/theme.py +385 -0
- freyja-0.0.0/freyja/theme/theme_style.py +34 -0
- freyja-0.0.0/freyja/utils/__init__.py +13 -0
- freyja-0.0.0/freyja/utils/ansi_string.py +157 -0
- freyja-0.0.0/freyja/utils/data_struct_util.py +66 -0
- freyja-0.0.0/freyja/utils/math_util.py +55 -0
- freyja-0.0.0/freyja/utils/text_util.py +73 -0
- freyja-0.0.0/pyproject.toml +131 -0
freyja-0.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2019] [Tangled Path]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
freyja-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: freyja
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Python Library that builds a complete CLI given one or more functions using introspection
|
|
5
|
+
Home-page: https://pypi.org/project/freyja/
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: cli,auto,introspection,argparse,command-line
|
|
8
|
+
Author: Steven Miers
|
|
9
|
+
Author-email: steven.miers@gmail.com
|
|
10
|
+
Requires-Python: >=3.13.7,<4.0.0
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
+
Classifier: Topic :: System :: Systems Administration
|
|
19
|
+
Classifier: Topic :: Utilities
|
|
20
|
+
Project-URL: Documentation, https://github.com/tangledpath/freyja/docs
|
|
21
|
+
Project-URL: Repository, https://github.com/tangledpath/freyja
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
# Freyja ⚡
|
|
27
|
+
**No-dependency, zero-configuration CLI tool to build command-line interfaces purely from your code.**
|
|
28
|
+
|
|
29
|
+
Transform your Python functions and classes into powerful command-line applications in seconds! Freyja uses introspection and type annotations to automatically generate professional CLIs with zero configuration required.
|
|
30
|
+
|
|
31
|
+
## Table of Contents
|
|
32
|
+
* [🚀 Why Freyja?](#-why-freyja)
|
|
33
|
+
* [⚡ Quick Start](#-quick-start)
|
|
34
|
+
* [🗂️ Module-based CLI](#️-module-based-cli)
|
|
35
|
+
* [🏗️ Class-based CLI](#️-class-based-cli)
|
|
36
|
+
* [Direct Methods Pattern](#direct-methods-pattern)
|
|
37
|
+
* [Inner Classes Pattern](#inner-classes-pattern)
|
|
38
|
+
* [✨ Key Features](#-key-features)
|
|
39
|
+
* [📚 Documentation](#-documentation)
|
|
40
|
+
* [🛠️ Development](#️-development)
|
|
41
|
+
* [⚙️ Requirements](#️-requirements)
|
|
42
|
+
|
|
43
|
+
## 🚀 Why Freyja?
|
|
44
|
+
|
|
45
|
+
**Build CLIs in under 5 minutes!** No configuration files, no complex setup, no learning curve. Just add type annotations to your functions and Freyja does the rest.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install freyja
|
|
49
|
+
# That's it! No dependencies, no configuration needed.
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Before Freyja:**
|
|
53
|
+
```bash
|
|
54
|
+
python script.py --config-file /path/to/config --database-host localhost --database-port 5432 --username admin --password secret --table-name users --action create --data '{"name": "Alice", "email": "alice@example.com"}'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**After Freyja:**
|
|
58
|
+
```bash
|
|
59
|
+
python script.py database--create-user --name Alice --email alice@example.com
|
|
60
|
+
# Global config handled automatically, clean syntax, built-in help
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## ⚡ Quick Start
|
|
64
|
+
|
|
65
|
+
**Step 1:** Install Freyja
|
|
66
|
+
```bash
|
|
67
|
+
pip install freyja
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Step 2:** Add type annotations to your functions
|
|
71
|
+
```python
|
|
72
|
+
def greet(name: str = "World", excited: bool = False) -> None:
|
|
73
|
+
"""Greet someone by name."""
|
|
74
|
+
greeting = f"Hello, {name}!"
|
|
75
|
+
if excited:
|
|
76
|
+
greeting += " 🎉"
|
|
77
|
+
print(greeting)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Step 3:** Add 3 lines of Freyja code
|
|
81
|
+
```python
|
|
82
|
+
from freyja import CLI
|
|
83
|
+
import sys
|
|
84
|
+
|
|
85
|
+
if __name__ == '__main__':
|
|
86
|
+
cli = CLI(sys.modules[__name__], title="My CLI")
|
|
87
|
+
cli.display()
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Step 4:** Use your new CLI!
|
|
91
|
+
```bash
|
|
92
|
+
python script.py greet --name Alice --excited
|
|
93
|
+
# Output: Hello, Alice! 🎉
|
|
94
|
+
|
|
95
|
+
python script.py --help
|
|
96
|
+
# Automatic help generation with beautiful formatting
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 🗂️ Module-based CLI
|
|
100
|
+
|
|
101
|
+
Perfect for functional programming styles and simple utilities. Every function becomes a command:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
# data_processor.py
|
|
105
|
+
from freyja import CLI
|
|
106
|
+
import sys
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def process_csv(input_file: str, output_format: str = "json", verbose: bool = False) -> None:
|
|
110
|
+
"""Process CSV file and convert to specified format."""
|
|
111
|
+
print(f"Processing {input_file} -> {output_format}")
|
|
112
|
+
if verbose:
|
|
113
|
+
print("Verbose mode enabled")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def analyze_logs(log_file: str, pattern: str, max_lines: int = 1000) -> None:
|
|
117
|
+
"""Analyze log files for specific patterns."""
|
|
118
|
+
print(f"Analyzing {log_file} for pattern: {pattern} (max {max_lines} lines)")
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if __name__ == '__main__':
|
|
122
|
+
cli = CLI(sys.modules[__name__], title="Data Processing Tools")
|
|
123
|
+
cli.display()
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Usage:**
|
|
127
|
+
```bash
|
|
128
|
+
python data_processor.py process-csv --input-file data.csv --output-format xml --verbose
|
|
129
|
+
python data_processor.py analyze-logs --log-file app.log --pattern "ERROR" --max-lines 500
|
|
130
|
+
python data_processor.py --help # Beautiful auto-generated help
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## 🏗️ Class-based CLI
|
|
134
|
+
|
|
135
|
+
Ideal for stateful applications and complex workflows. Supports two powerful patterns:
|
|
136
|
+
|
|
137
|
+
### Direct Methods Pattern
|
|
138
|
+
|
|
139
|
+
Simple and clean - each method becomes a command:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
# calculator.py
|
|
143
|
+
from freyja import CLI
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class Calculator:
|
|
147
|
+
"""Advanced calculator with memory and history."""
|
|
148
|
+
|
|
149
|
+
def __init__(self, precision: int = 2, memory_enabled: bool = True):
|
|
150
|
+
"""Initialize calculator with global settings."""
|
|
151
|
+
self.precision = precision
|
|
152
|
+
self.memory = 0 if memory_enabled else None
|
|
153
|
+
|
|
154
|
+
def add(self, a: float, b: float, store_result: bool = False) -> None:
|
|
155
|
+
"""Add two numbers together."""
|
|
156
|
+
result = round(a + b, self.precision)
|
|
157
|
+
print(f"{a} + {b} = {result}")
|
|
158
|
+
|
|
159
|
+
if store_result and self.memory is not None:
|
|
160
|
+
self.memory = result
|
|
161
|
+
print(f"Result stored in memory: {result}")
|
|
162
|
+
|
|
163
|
+
def multiply(self, a: float, b: float) -> None:
|
|
164
|
+
"""Multiply two numbers."""
|
|
165
|
+
result = round(a * b, self.precision)
|
|
166
|
+
print(f"{a} × {b} = {result}")
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
if __name__ == '__main__':
|
|
170
|
+
cli = CLI(Calculator, title="Advanced Calculator")
|
|
171
|
+
cli.display()
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Usage:**
|
|
175
|
+
```bash
|
|
176
|
+
python calculator.py --precision 4 add --a 3.14159 --b 2.71828 --store-result
|
|
177
|
+
# Output: 3.14159 + 2.71828 = 5.8599
|
|
178
|
+
# Result stored in memory: 5.8599
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Inner Classes Pattern
|
|
182
|
+
|
|
183
|
+
Organize complex applications with flat double-dash commands:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
# project_manager.py
|
|
187
|
+
from freyja import CLI
|
|
188
|
+
from pathlib import Path
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class ProjectManager:
|
|
192
|
+
"""Complete project management suite with organized command structure."""
|
|
193
|
+
|
|
194
|
+
def __init__(self, config_file: str = "config.json", debug: bool = False):
|
|
195
|
+
"""Initialize with global settings."""
|
|
196
|
+
self.config_file = config_file
|
|
197
|
+
self.debug = debug
|
|
198
|
+
|
|
199
|
+
class Database:
|
|
200
|
+
"""Database operations and management."""
|
|
201
|
+
|
|
202
|
+
def __init__(self, connection_string: str = "sqlite:///projects.db", timeout: int = 30):
|
|
203
|
+
"""Initialize database connection."""
|
|
204
|
+
self.connection_string = connection_string
|
|
205
|
+
self.timeout = timeout
|
|
206
|
+
|
|
207
|
+
def migrate(self, version: str = "latest", dry_run: bool = False) -> None:
|
|
208
|
+
"""Run database migrations."""
|
|
209
|
+
action = "Would run" if dry_run else "Running"
|
|
210
|
+
print(f"{action} migration to version: {version}")
|
|
211
|
+
print(f"Connection: {self.connection_string}")
|
|
212
|
+
|
|
213
|
+
def backup(self, output_path: Path, compress: bool = True) -> None:
|
|
214
|
+
"""Create database backup."""
|
|
215
|
+
compression = "compressed" if compress else "uncompressed"
|
|
216
|
+
print(f"Creating {compression} backup at: {output_path}")
|
|
217
|
+
|
|
218
|
+
class Projects:
|
|
219
|
+
"""Project creation and management operations."""
|
|
220
|
+
|
|
221
|
+
def __init__(self, workspace: str = "./projects", auto_save: bool = True):
|
|
222
|
+
"""Initialize project operations."""
|
|
223
|
+
self.workspace = workspace
|
|
224
|
+
self.auto_save = auto_save
|
|
225
|
+
|
|
226
|
+
def create(self, name: str, template: str = "basic", description: str = "") -> None:
|
|
227
|
+
"""Create a new project from template."""
|
|
228
|
+
print(f"Creating project '{name}' using '{template}' template")
|
|
229
|
+
print(f"Workspace: {self.workspace}")
|
|
230
|
+
print(f"Description: {description}")
|
|
231
|
+
print(f"Auto-save: {'enabled' if self.auto_save else 'disabled'}")
|
|
232
|
+
|
|
233
|
+
def deploy(self, project_name: str, environment: str = "staging", force: bool = False) -> None:
|
|
234
|
+
"""Deploy project to specified environment."""
|
|
235
|
+
action = "Force deploying" if force else "Deploying"
|
|
236
|
+
print(f"{action} {project_name} to {environment}")
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
if __name__ == '__main__':
|
|
240
|
+
cli = CLI(ProjectManager, title="Project Management Suite")
|
|
241
|
+
cli.display()
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Usage:**
|
|
245
|
+
```bash
|
|
246
|
+
# Global + Sub-global + Command arguments (all flat)
|
|
247
|
+
python project_manager.py --config-file prod.json --debug \
|
|
248
|
+
database--migrate --connection-string postgres://prod --version 2.1.0 --dry-run
|
|
249
|
+
|
|
250
|
+
# Create new project with custom workspace
|
|
251
|
+
python project_manager.py projects--create --workspace /prod/projects --auto-save \
|
|
252
|
+
--name "web-app" --template "react" --description "Production web application"
|
|
253
|
+
|
|
254
|
+
# Deploy with force flag
|
|
255
|
+
python project_manager.py projects--deploy --project-name web-app --environment production --force
|
|
256
|
+
|
|
257
|
+
# Beautiful help shows all flat commands organized by group
|
|
258
|
+
python project_manager.py --help
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## ✨ Key Features
|
|
262
|
+
|
|
263
|
+
🚀 **Zero Configuration** - Works out of the box with just type annotations
|
|
264
|
+
⚡ **Lightning Fast** - No runtime dependencies, minimal overhead
|
|
265
|
+
🎯 **Type Safe** - Automatic validation from your type hints
|
|
266
|
+
📚 **Auto Documentation** - Help text generated from your docstrings
|
|
267
|
+
🎨 **Beautiful Output** - Professional themes and formatting
|
|
268
|
+
🔧 **Flexible Architecture** - Module-based or class-based patterns
|
|
269
|
+
📦 **No Dependencies** - Uses only Python standard library
|
|
270
|
+
🌈 **Shell Completion** - Bash, Zsh, Fish, and PowerShell support
|
|
271
|
+
✅ **Production Ready** - Battle-tested in enterprise applications
|
|
272
|
+
|
|
273
|
+
## 📚 Documentation
|
|
274
|
+
|
|
275
|
+
**[📖 Complete Documentation Hub](docs/README.md)** - Everything you need to master Freyja
|
|
276
|
+
|
|
277
|
+
### Quick Links
|
|
278
|
+
* **[🚀 Getting Started](docs/getting-started/README.md)** - Installation and first steps
|
|
279
|
+
* **[👤 User Guide](docs/user-guide/README.md)** - Comprehensive guides for both CLI modes
|
|
280
|
+
* **[⚙️ Features](docs/features/README.md)** - Type annotations, themes, completion, and more
|
|
281
|
+
* **[📋 Examples & Best Practices](docs/guides/README.md)** - Real-world examples and patterns
|
|
282
|
+
* **[❓ FAQ](docs/faq.md)** - Frequently asked questions
|
|
283
|
+
* **[🔧 API Reference](docs/reference/README.md)** - Complete API documentation
|
|
284
|
+
|
|
285
|
+
## 🛠️ Development
|
|
286
|
+
|
|
287
|
+
**[📖 Development Guide](CLAUDE.md)** - Comprehensive guide for contributors
|
|
288
|
+
|
|
289
|
+
### Quick Setup
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
# Clone and setup
|
|
293
|
+
git clone https://github.com/tangledpath/freyja.git
|
|
294
|
+
cd freyja
|
|
295
|
+
|
|
296
|
+
# Install Poetry and setup environment
|
|
297
|
+
curl -sSL https://install.python-poetry.org | python3 -
|
|
298
|
+
./bin/setup-dev.sh
|
|
299
|
+
|
|
300
|
+
# Run tests and examples
|
|
301
|
+
./bin/test.sh
|
|
302
|
+
poetry run python examples/mod_example.py --help
|
|
303
|
+
poetry run python examples/cls_example.py --help
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Development Commands
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
poetry install # Install dependencies
|
|
310
|
+
./bin/test.sh # Run tests with coverage
|
|
311
|
+
./bin/lint.sh # Run all linters and formatters
|
|
312
|
+
poetry build # Build package
|
|
313
|
+
./bin/publish.sh # Publish to PyPI (maintainers)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## ⚙️ Requirements
|
|
317
|
+
|
|
318
|
+
* **Python 3.13.5+** (recommended) or Python 3.8+
|
|
319
|
+
* **Zero runtime dependencies** - uses only Python standard library
|
|
320
|
+
* **Type annotations required** - for automatic CLI generation
|
|
321
|
+
* **Docstrings recommended** - for automatic help text generation
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
**Ready to transform your Python code into powerful CLIs?**
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
pip install freyja
|
|
329
|
+
# Start building amazing command-line tools in minutes! ⚡
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
**[📚 Get Started Now →](docs/getting-started/README.md)**
|
freyja-0.0.0/README.md
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Freyja ⚡
|
|
4
|
+
**No-dependency, zero-configuration CLI tool to build command-line interfaces purely from your code.**
|
|
5
|
+
|
|
6
|
+
Transform your Python functions and classes into powerful command-line applications in seconds! Freyja uses introspection and type annotations to automatically generate professional CLIs with zero configuration required.
|
|
7
|
+
|
|
8
|
+
## Table of Contents
|
|
9
|
+
* [🚀 Why Freyja?](#-why-freyja)
|
|
10
|
+
* [⚡ Quick Start](#-quick-start)
|
|
11
|
+
* [🗂️ Module-based CLI](#️-module-based-cli)
|
|
12
|
+
* [🏗️ Class-based CLI](#️-class-based-cli)
|
|
13
|
+
* [Direct Methods Pattern](#direct-methods-pattern)
|
|
14
|
+
* [Inner Classes Pattern](#inner-classes-pattern)
|
|
15
|
+
* [✨ Key Features](#-key-features)
|
|
16
|
+
* [📚 Documentation](#-documentation)
|
|
17
|
+
* [🛠️ Development](#️-development)
|
|
18
|
+
* [⚙️ Requirements](#️-requirements)
|
|
19
|
+
|
|
20
|
+
## 🚀 Why Freyja?
|
|
21
|
+
|
|
22
|
+
**Build CLIs in under 5 minutes!** No configuration files, no complex setup, no learning curve. Just add type annotations to your functions and Freyja does the rest.
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install freyja
|
|
26
|
+
# That's it! No dependencies, no configuration needed.
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Before Freyja:**
|
|
30
|
+
```bash
|
|
31
|
+
python script.py --config-file /path/to/config --database-host localhost --database-port 5432 --username admin --password secret --table-name users --action create --data '{"name": "Alice", "email": "alice@example.com"}'
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**After Freyja:**
|
|
35
|
+
```bash
|
|
36
|
+
python script.py database--create-user --name Alice --email alice@example.com
|
|
37
|
+
# Global config handled automatically, clean syntax, built-in help
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## ⚡ Quick Start
|
|
41
|
+
|
|
42
|
+
**Step 1:** Install Freyja
|
|
43
|
+
```bash
|
|
44
|
+
pip install freyja
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Step 2:** Add type annotations to your functions
|
|
48
|
+
```python
|
|
49
|
+
def greet(name: str = "World", excited: bool = False) -> None:
|
|
50
|
+
"""Greet someone by name."""
|
|
51
|
+
greeting = f"Hello, {name}!"
|
|
52
|
+
if excited:
|
|
53
|
+
greeting += " 🎉"
|
|
54
|
+
print(greeting)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Step 3:** Add 3 lines of Freyja code
|
|
58
|
+
```python
|
|
59
|
+
from freyja import CLI
|
|
60
|
+
import sys
|
|
61
|
+
|
|
62
|
+
if __name__ == '__main__':
|
|
63
|
+
cli = CLI(sys.modules[__name__], title="My CLI")
|
|
64
|
+
cli.display()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Step 4:** Use your new CLI!
|
|
68
|
+
```bash
|
|
69
|
+
python script.py greet --name Alice --excited
|
|
70
|
+
# Output: Hello, Alice! 🎉
|
|
71
|
+
|
|
72
|
+
python script.py --help
|
|
73
|
+
# Automatic help generation with beautiful formatting
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 🗂️ Module-based CLI
|
|
77
|
+
|
|
78
|
+
Perfect for functional programming styles and simple utilities. Every function becomes a command:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# data_processor.py
|
|
82
|
+
from freyja import CLI
|
|
83
|
+
import sys
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def process_csv(input_file: str, output_format: str = "json", verbose: bool = False) -> None:
|
|
87
|
+
"""Process CSV file and convert to specified format."""
|
|
88
|
+
print(f"Processing {input_file} -> {output_format}")
|
|
89
|
+
if verbose:
|
|
90
|
+
print("Verbose mode enabled")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def analyze_logs(log_file: str, pattern: str, max_lines: int = 1000) -> None:
|
|
94
|
+
"""Analyze log files for specific patterns."""
|
|
95
|
+
print(f"Analyzing {log_file} for pattern: {pattern} (max {max_lines} lines)")
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == '__main__':
|
|
99
|
+
cli = CLI(sys.modules[__name__], title="Data Processing Tools")
|
|
100
|
+
cli.display()
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Usage:**
|
|
104
|
+
```bash
|
|
105
|
+
python data_processor.py process-csv --input-file data.csv --output-format xml --verbose
|
|
106
|
+
python data_processor.py analyze-logs --log-file app.log --pattern "ERROR" --max-lines 500
|
|
107
|
+
python data_processor.py --help # Beautiful auto-generated help
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 🏗️ Class-based CLI
|
|
111
|
+
|
|
112
|
+
Ideal for stateful applications and complex workflows. Supports two powerful patterns:
|
|
113
|
+
|
|
114
|
+
### Direct Methods Pattern
|
|
115
|
+
|
|
116
|
+
Simple and clean - each method becomes a command:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
# calculator.py
|
|
120
|
+
from freyja import CLI
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class Calculator:
|
|
124
|
+
"""Advanced calculator with memory and history."""
|
|
125
|
+
|
|
126
|
+
def __init__(self, precision: int = 2, memory_enabled: bool = True):
|
|
127
|
+
"""Initialize calculator with global settings."""
|
|
128
|
+
self.precision = precision
|
|
129
|
+
self.memory = 0 if memory_enabled else None
|
|
130
|
+
|
|
131
|
+
def add(self, a: float, b: float, store_result: bool = False) -> None:
|
|
132
|
+
"""Add two numbers together."""
|
|
133
|
+
result = round(a + b, self.precision)
|
|
134
|
+
print(f"{a} + {b} = {result}")
|
|
135
|
+
|
|
136
|
+
if store_result and self.memory is not None:
|
|
137
|
+
self.memory = result
|
|
138
|
+
print(f"Result stored in memory: {result}")
|
|
139
|
+
|
|
140
|
+
def multiply(self, a: float, b: float) -> None:
|
|
141
|
+
"""Multiply two numbers."""
|
|
142
|
+
result = round(a * b, self.precision)
|
|
143
|
+
print(f"{a} × {b} = {result}")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
if __name__ == '__main__':
|
|
147
|
+
cli = CLI(Calculator, title="Advanced Calculator")
|
|
148
|
+
cli.display()
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Usage:**
|
|
152
|
+
```bash
|
|
153
|
+
python calculator.py --precision 4 add --a 3.14159 --b 2.71828 --store-result
|
|
154
|
+
# Output: 3.14159 + 2.71828 = 5.8599
|
|
155
|
+
# Result stored in memory: 5.8599
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Inner Classes Pattern
|
|
159
|
+
|
|
160
|
+
Organize complex applications with flat double-dash commands:
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
# project_manager.py
|
|
164
|
+
from freyja import CLI
|
|
165
|
+
from pathlib import Path
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class ProjectManager:
|
|
169
|
+
"""Complete project management suite with organized command structure."""
|
|
170
|
+
|
|
171
|
+
def __init__(self, config_file: str = "config.json", debug: bool = False):
|
|
172
|
+
"""Initialize with global settings."""
|
|
173
|
+
self.config_file = config_file
|
|
174
|
+
self.debug = debug
|
|
175
|
+
|
|
176
|
+
class Database:
|
|
177
|
+
"""Database operations and management."""
|
|
178
|
+
|
|
179
|
+
def __init__(self, connection_string: str = "sqlite:///projects.db", timeout: int = 30):
|
|
180
|
+
"""Initialize database connection."""
|
|
181
|
+
self.connection_string = connection_string
|
|
182
|
+
self.timeout = timeout
|
|
183
|
+
|
|
184
|
+
def migrate(self, version: str = "latest", dry_run: bool = False) -> None:
|
|
185
|
+
"""Run database migrations."""
|
|
186
|
+
action = "Would run" if dry_run else "Running"
|
|
187
|
+
print(f"{action} migration to version: {version}")
|
|
188
|
+
print(f"Connection: {self.connection_string}")
|
|
189
|
+
|
|
190
|
+
def backup(self, output_path: Path, compress: bool = True) -> None:
|
|
191
|
+
"""Create database backup."""
|
|
192
|
+
compression = "compressed" if compress else "uncompressed"
|
|
193
|
+
print(f"Creating {compression} backup at: {output_path}")
|
|
194
|
+
|
|
195
|
+
class Projects:
|
|
196
|
+
"""Project creation and management operations."""
|
|
197
|
+
|
|
198
|
+
def __init__(self, workspace: str = "./projects", auto_save: bool = True):
|
|
199
|
+
"""Initialize project operations."""
|
|
200
|
+
self.workspace = workspace
|
|
201
|
+
self.auto_save = auto_save
|
|
202
|
+
|
|
203
|
+
def create(self, name: str, template: str = "basic", description: str = "") -> None:
|
|
204
|
+
"""Create a new project from template."""
|
|
205
|
+
print(f"Creating project '{name}' using '{template}' template")
|
|
206
|
+
print(f"Workspace: {self.workspace}")
|
|
207
|
+
print(f"Description: {description}")
|
|
208
|
+
print(f"Auto-save: {'enabled' if self.auto_save else 'disabled'}")
|
|
209
|
+
|
|
210
|
+
def deploy(self, project_name: str, environment: str = "staging", force: bool = False) -> None:
|
|
211
|
+
"""Deploy project to specified environment."""
|
|
212
|
+
action = "Force deploying" if force else "Deploying"
|
|
213
|
+
print(f"{action} {project_name} to {environment}")
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
if __name__ == '__main__':
|
|
217
|
+
cli = CLI(ProjectManager, title="Project Management Suite")
|
|
218
|
+
cli.display()
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
**Usage:**
|
|
222
|
+
```bash
|
|
223
|
+
# Global + Sub-global + Command arguments (all flat)
|
|
224
|
+
python project_manager.py --config-file prod.json --debug \
|
|
225
|
+
database--migrate --connection-string postgres://prod --version 2.1.0 --dry-run
|
|
226
|
+
|
|
227
|
+
# Create new project with custom workspace
|
|
228
|
+
python project_manager.py projects--create --workspace /prod/projects --auto-save \
|
|
229
|
+
--name "web-app" --template "react" --description "Production web application"
|
|
230
|
+
|
|
231
|
+
# Deploy with force flag
|
|
232
|
+
python project_manager.py projects--deploy --project-name web-app --environment production --force
|
|
233
|
+
|
|
234
|
+
# Beautiful help shows all flat commands organized by group
|
|
235
|
+
python project_manager.py --help
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## ✨ Key Features
|
|
239
|
+
|
|
240
|
+
🚀 **Zero Configuration** - Works out of the box with just type annotations
|
|
241
|
+
⚡ **Lightning Fast** - No runtime dependencies, minimal overhead
|
|
242
|
+
🎯 **Type Safe** - Automatic validation from your type hints
|
|
243
|
+
📚 **Auto Documentation** - Help text generated from your docstrings
|
|
244
|
+
🎨 **Beautiful Output** - Professional themes and formatting
|
|
245
|
+
🔧 **Flexible Architecture** - Module-based or class-based patterns
|
|
246
|
+
📦 **No Dependencies** - Uses only Python standard library
|
|
247
|
+
🌈 **Shell Completion** - Bash, Zsh, Fish, and PowerShell support
|
|
248
|
+
✅ **Production Ready** - Battle-tested in enterprise applications
|
|
249
|
+
|
|
250
|
+
## 📚 Documentation
|
|
251
|
+
|
|
252
|
+
**[📖 Complete Documentation Hub](docs/README.md)** - Everything you need to master Freyja
|
|
253
|
+
|
|
254
|
+
### Quick Links
|
|
255
|
+
* **[🚀 Getting Started](docs/getting-started/README.md)** - Installation and first steps
|
|
256
|
+
* **[👤 User Guide](docs/user-guide/README.md)** - Comprehensive guides for both CLI modes
|
|
257
|
+
* **[⚙️ Features](docs/features/README.md)** - Type annotations, themes, completion, and more
|
|
258
|
+
* **[📋 Examples & Best Practices](docs/guides/README.md)** - Real-world examples and patterns
|
|
259
|
+
* **[❓ FAQ](docs/faq.md)** - Frequently asked questions
|
|
260
|
+
* **[🔧 API Reference](docs/reference/README.md)** - Complete API documentation
|
|
261
|
+
|
|
262
|
+
## 🛠️ Development
|
|
263
|
+
|
|
264
|
+
**[📖 Development Guide](CLAUDE.md)** - Comprehensive guide for contributors
|
|
265
|
+
|
|
266
|
+
### Quick Setup
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
# Clone and setup
|
|
270
|
+
git clone https://github.com/tangledpath/freyja.git
|
|
271
|
+
cd freyja
|
|
272
|
+
|
|
273
|
+
# Install Poetry and setup environment
|
|
274
|
+
curl -sSL https://install.python-poetry.org | python3 -
|
|
275
|
+
./bin/setup-dev.sh
|
|
276
|
+
|
|
277
|
+
# Run tests and examples
|
|
278
|
+
./bin/test.sh
|
|
279
|
+
poetry run python examples/mod_example.py --help
|
|
280
|
+
poetry run python examples/cls_example.py --help
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Development Commands
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
poetry install # Install dependencies
|
|
287
|
+
./bin/test.sh # Run tests with coverage
|
|
288
|
+
./bin/lint.sh # Run all linters and formatters
|
|
289
|
+
poetry build # Build package
|
|
290
|
+
./bin/publish.sh # Publish to PyPI (maintainers)
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
## ⚙️ Requirements
|
|
294
|
+
|
|
295
|
+
* **Python 3.13.5+** (recommended) or Python 3.8+
|
|
296
|
+
* **Zero runtime dependencies** - uses only Python standard library
|
|
297
|
+
* **Type annotations required** - for automatic CLI generation
|
|
298
|
+
* **Docstrings recommended** - for automatic help text generation
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
**Ready to transform your Python code into powerful CLIs?**
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
pip install freyja
|
|
306
|
+
# Start building amazing command-line tools in minutes! ⚡
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**[📚 Get Started Now →](docs/getting-started/README.md)**
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Freyja: Zero-configuration FreyjaCLI generator from classes/module introspection.
|
|
3
|
+
Uses class/method/function introspection, typehints, and docstrings to build
|
|
4
|
+
a fully functional FreyjaCLI. Command groups can be made with inner-classes,
|
|
5
|
+
effectively making subclasses.
|
|
6
|
+
"""
|
|
7
|
+
from .freyja_cli import FreyjaCLI
|
|
8
|
+
__all__ = [FreyjaCLI]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from .class_handler import ClassHandler
|
|
2
|
+
from .execution_coordinator import ExecutionCoordinator
|
|
3
|
+
from .enums import TargetMode
|
|
4
|
+
from .system import SystemClassBuilder
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
ClassHandler,
|
|
8
|
+
ExecutionCoordinator,
|
|
9
|
+
SystemClassBuilder,
|
|
10
|
+
TargetMode,
|
|
11
|
+
]
|