-
Notifications
You must be signed in to change notification settings - Fork 384
Added the list command. #359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d45b8de
7602b5e
03988e8
cae3844
ccaac15
05a9ba8
215404c
df20212
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,12 +1,14 @@ | ||||||||||||||||||||||||||||||||||
| import typer | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| from commands import hello | ||||||||||||||||||||||||||||||||||
| from commands import list | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Create the root CLI app | ||||||||||||||||||||||||||||||||||
| app = typer.Typer(help="101 Linux Commands CLI 🚀") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Register subcommands | ||||||||||||||||||||||||||||||||||
| app.add_typer(hello.app, name="hello") | ||||||||||||||||||||||||||||||||||
| app.add_typer(list.app, name="list") | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| from commands import list | |
| # Create the root CLI app | |
| app = typer.Typer(help="101 Linux Commands CLI 🚀") | |
| # Register subcommands | |
| app.add_typer(hello.app, name="hello") | |
| app.add_typer(list.app, name="list") | |
| from commands import list as list_commands | |
| # Create the root CLI app | |
| app = typer.Typer(help="101 Linux Commands CLI 🚀") | |
| # Register subcommands | |
| app.add_typer(hello.app, name="hello") | |
| app.add_typer(list_commands.app, name="list") |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |||||
| app = typer.Typer(help="Hello command group") | ||||||
|
|
||||||
|
|
||||||
| @app.command() | ||||||
| @app.callback(invoke_without_command=True) | ||||||
|
||||||
| @app.callback(invoke_without_command=True) | |
| @app.command() |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||||||
| import typer | ||||||||||||||
|
|
||||||||||||||
| app = typer.Typer(help="List the commands available on Linux.") | ||||||||||||||
|
|
||||||||||||||
| @app.callback(invoke_without_command=True) | ||||||||||||||
| def list(): | ||||||||||||||
| commands = [ | ||||||||||||||
| "ls - List directory contents.", | ||||||||||||||
| "cd - Change directory.", | ||||||||||||||
| "pwd - Print working directory.", | ||||||||||||||
|
Comment on lines
+9
to
+11
|
||||||||||||||
| "ls - List directory contents.", | |
| "cd - Change directory.", | |
| "pwd - Print working directory.", | |
| "ls - List directory contents", | |
| "cd - Change directory", | |
| "pwd - Print working directory", |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,10 +53,25 @@ def test_hello_help(): | |||||||||||||||||
| assert result.returncode == 0 | ||||||||||||||||||
| assert "Hello command group" in result.stdout | ||||||||||||||||||
|
|
||||||||||||||||||
| def test_list_command(): | ||||||||||||||||||
| """Test the list command.""" | ||||||||||||||||||
| result = subprocess.run( | ||||||||||||||||||
| [sys.executable, "cli.py", "list"], | ||||||||||||||||||
| capture_output=True, | ||||||||||||||||||
| text=True, | ||||||||||||||||||
| cwd=os.path.dirname(__file__), | ||||||||||||||||||
| ) | ||||||||||||||||||
| assert result.returncode == 0 | ||||||||||||||||||
| assert "ls - List directory contents" in result.stdout | ||||||||||||||||||
| assert "cd - Change directory" in result.stdout | ||||||||||||||||||
| assert "pwd - Print working directory" in result.stdout | ||||||||||||||||||
| assert "cat - Concatenate and display files" in result.stdout | ||||||||||||||||||
|
||||||||||||||||||
| assert "ls - List directory contents" in result.stdout | |
| assert "cd - Change directory" in result.stdout | |
| assert "pwd - Print working directory" in result.stdout | |
| assert "cat - Concatenate and display files" in result.stdout | |
| assert "ls - List directory contents." in result.stdout | |
| assert "cd - Change directory." in result.stdout | |
| assert "pwd - Print working directory." in result.stdout | |
| assert "cat - Concatenate and display files." in result.stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing a module named list masks the built-in list type in this scope, reducing clarity; renaming the module (e.g., commands_list) or importing with an alias (from commands import list as list_commands) would avoid overshadowing and make intent clearer. Update the registration accordingly (app.add_typer(list_commands.app, name="list")).