File size: 5,720 Bytes
f56729d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9dd307
f56729d
 
e9dd307
f56729d
 
e9dd307
f56729d
 
e9dd307
f56729d
45ac00a
e9dd307
45ac00a
 
e9dd307
45ac00a
 
e9dd307
 
 
 
45ac00a
f56729d
 
 
 
 
 
45ac00a
 
 
 
 
 
 
 
 
 
f56729d
 
 
e9dd307
 
 
f56729d
 
 
 
 
 
 
 
 
45ac00a
 
 
 
 
 
 
 
 
f56729d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""
Help command for the Folio CLI.

This module provides the help command for displaying information about available commands.
"""

from typing import Any

from rich.box import ROUNDED
from rich.table import Table


def help_command(args: list[str], state: dict[str, Any], console):  # noqa: ARG001
    """Show help information.

    Args:
        args: Command arguments
        state: Application state
        console: Rich console for output
    """
    from src.focli.commands import get_command_registry

    # Get the command registry
    commands = get_command_registry()

    # Check if we're showing help for a specific command
    if args and args[0] in commands:
        command = args[0]
        command_info = commands[command]

        console.print(f"\n[bold]Help for command:[/bold] [cyan]{command}[/cyan]")
        console.print(f"\n{command_info['help']}\n")

        # Show subcommands if available
        if command_info.get("subcommands"):
            console.print("[bold]Subcommands:[/bold]")
            for subcommand in command_info["subcommands"]:
                console.print(f"  [cyan]{subcommand}[/cyan]")
            console.print("")

        # Show usage examples based on the command
        console.print("[bold]Usage examples:[/bold]")

        if command == "simulate":
            console.print(
                "  [green]simulate[/green] - Run a simulation with default parameters (SPY benchmark)"
            )
            console.print(
                "  [green]simulate --range 10 --steps 21[/green] - Run a simulation with ±10% range and 21 steps"
            )
            console.print(
                "  [green]simulate --focus SPY,AAPL[/green] - Run a simulation focusing on specific tickers"
            )
            console.print(
                "  [green]simulate --detailed[/green] - Run a simulation with detailed position analysis"
            )
            console.print(
                "  [green]simulate --preset detailed[/green] - Run a simulation using a saved preset"
            )
            console.print(
                "  [green]simulate --save-preset my_preset[/green] - Save current parameters as a preset"
            )
            console.print(
                "  [green]simulate --filter options[/green] - Run a simulation only on positions with options"
            )
            console.print(
                "  [green]simulate spy[/green] - Explicitly specify SPY benchmark (same as 'simulate')"
            )

        elif command == "position":
            console.print(
                "  [green]position SPY[/green] - Show details for the SPY position"
            )
            console.print(
                "  [green]position AAPL details --detailed[/green] - Show detailed information for the AAPL position"
            )
            console.print(
                "  [green]position SPY risk[/green] - Show risk analysis for the SPY position"
            )
            console.print(
                "  [green]position AAPL simulate[/green] - Simulate the AAPL position with SPY changes"
            )
            console.print(
                "  [green]position AAPL simulate --range 15 --steps 11[/green] - Customize the position simulation"
            )

        elif command == "portfolio":
            console.print(
                "  [green]portfolio[/green] - Show a summary of the portfolio (same as 'portfolio summary')"
            )
            console.print(
                "  [green]portfolio summary[/green] - Show a summary of the portfolio"
            )
            console.print(
                "  [green]portfolio load path/to/portfolio.csv[/green] - Load a portfolio from a CSV file"
            )
            console.print(
                "  [green]portfolio list[/green] - List all positions in the portfolio"
            )
            console.print(
                "  [green]portfolio list --focus SPY,AAPL[/green] - List specific positions"
            )
            console.print(
                "  [green]portfolio list --options[/green] - List only positions with options"
            )
            console.print(
                "  [green]portfolio list --sort value[/green] - Sort positions by value"
            )

        elif command == "help":
            console.print("  [green]help[/green] - Show this help message")
            console.print(
                "  [green]help simulate[/green] - Show help for the simulate command"
            )

        elif command == "exit":
            console.print("  [green]exit[/green] - Exit the application")

        console.print("")

    else:
        # Show general help
        console.print("\n[bold cyan]Folio CLI Help[/bold cyan]")
        console.print("\nAvailable commands:\n")

        # Create a table of commands
        table = Table(box=ROUNDED)
        table.add_column("Command", style="cyan")
        table.add_column("Description", style="green")
        table.add_column("Subcommands", style="yellow")

        # Add rows for each command
        for name, info in commands.items():
            subcommands = (
                ", ".join(info.get("subcommands", []))
                if info.get("subcommands")
                else ""
            )
            table.add_row(name, info["help"], subcommands)

        console.print(table)

        # Show general usage
        console.print("\n[bold]General usage:[/bold]")
        console.print("  Type a command followed by any arguments or options.")
        console.print(
            "  Use [cyan]help <command>[/cyan] to get help for a specific command."
        )
        console.print("  Use [cyan]exit[/cyan] to exit the application.")
        console.print("")