forked from The-DevOps-Daily/devops-daily
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow.py
More file actions
98 lines (84 loc) · 3.03 KB
/
show.py
File metadata and controls
98 lines (84 loc) · 3.03 KB
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
from typing import Dict, TypedDict
import typer
class CommandInfo(TypedDict):
description: str
usage: str
example: str
notes: str
COMMANDS: Dict[str, CommandInfo] = {
"ls": {
"description": (
"List information about the files in the current directory (the default). "
"Options can be used to modify the output format, sort order, and more."
),
"usage": "ls [OPTION]... [FILE]...",
"example": "ls -la /var/log",
"notes": (
"- `-l` : use a long listing format\n"
"- `-a` : show hidden files (starting with `.`)\n"
"- `-h` : with -l, print sizes in human-readable format (e.g., 1K, 234M)"
),
},
"grep": {
"description": (
"Search input files for lines containing a match to the given PATTERN. "
"Often used for filtering log files or searching through code."
),
"usage": "grep [OPTION]... PATTERN [FILE]...",
"example": 'grep -R "TODO" .',
"notes": (
"- `-i` : ignore case distinctions\n"
"- `-R` : recursively search subdirectories\n"
"- `-n` : show line numbers of matches"
),
},
"cat": {
"description": (
"Concatenate files and print on the standard output. "
"Often used to quickly view file contents."
),
"usage": "cat [OPTION]... [FILE]...",
"example": "cat /etc/passwd",
"notes": (
"- `-n` : number all output lines\n"
"- `-b` : number non-blank lines\n"
"- Use with pipes: `cat file.txt | grep pattern`"
),
},
"mkdir": {
"description": (
"Create directories if they do not already exist. "
"By default, it creates a single directory."
),
"usage": "mkdir [OPTION]... DIRECTORY...",
"example": "mkdir -p projects/python/app",
"notes": (
"- `-p` : create parent directories as needed\n"
"- `-v` : print a message for each created directory"
),
},
}
def show(
command: str = typer.Argument(..., help="Linux command to show details for")
) -> None:
"""
Display description, usage, examples, and notes for a given Linux command.
"""
key = command.strip()
info = COMMANDS.get(key)
if not info:
typer.secho(
f"✖ Unknown command '{command}'. Try one of: {', '.join(sorted(COMMANDS))}",
err=True,
fg=typer.colors.RED,
)
raise typer.Exit(code=1)
typer.secho(f"\nCommand: {key}\n", fg=typer.colors.CYAN, bold=True)
typer.secho("Description:", fg=typer.colors.MAGENTA, bold=True)
typer.echo(f" {info['description']}\n")
typer.secho("Usage:", fg=typer.colors.MAGENTA, bold=True)
typer.echo(f" {info['usage']}\n")
typer.secho("Example:", fg=typer.colors.MAGENTA, bold=True)
typer.echo(f" {info['example']}\n")
typer.secho("Notes:", fg=typer.colors.MAGENTA, bold=True)
typer.echo(f"{info['notes']}\n")