Skip to content

Added the list command.#359

Merged
bobbyiliev merged 8 commits intoThe-DevOps-Daily:mainfrom
devanshsonii:list-command
Oct 2, 2025
Merged

Added the list command.#359
bobbyiliev merged 8 commits intoThe-DevOps-Daily:mainfrom
devanshsonii:list-command

Conversation

@devanshsonii
Copy link
Contributor

What type of PR is this? (check all applicable)

  • ♻️ Refactor
  • ✨ New Chapter
  • 🐛 Bug Fix/Typo
  • 👷 Optimization
  • 📝 Documentation Update
  • 🚩 Other

Description

Added the list command with some dummy commands like cd, pwd etc.
Also fixed the invoke without command on dummy command hello

Related Tickets & Documents

Resolves #329

Added to documentation?

  • 📜 readme
  • 🙅 no documentation needed

[optional] What gif best describes this PR or how it makes you feel?

Copy link
Collaborator

@bobbyiliev bobbyiliev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The CI seems to be failing.

Also, maybe we should dynamically get the list of available commands from the ebook chapters?

@bobbyiliev bobbyiliev requested a review from Copilot October 1, 2025 14:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new list subcommand to display sample Linux commands and modifies the hello command behavior to run without specifying the greet subcommand. Updates tests to cover the new list command but does not adjust existing hello tests to reflect the decorator change.

  • Added list Typer app with a callback that prints a static list of commands
  • Changed hello command from a subcommand (@app.command) to a callback (@app.callback) but left tests invoking the old subcommand form
  • Added a test for the list command output

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
cli/commands/list.py New list command callback printing command descriptions.
cli/commands/hello.py Converted greet command into a callback invoked without a subcommand.
cli/cli.py Registered new list subcommand; imported list module.
cli/test_cli.py Added test for list command; kept previous hello tests unchanged.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.



@app.command()
@app.callback(invoke_without_command=True)
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing greet from a command to a callback removes the hello greet subcommand, but tests still invoke hello greet; this will cause those tests (and existing CLI usage) to fail. Either revert to @app.command() (and possibly add a separate callback if needed) or update tests and documentation to invoke hello (without greet) and use --name when desired.

Suggested change
@app.callback(invoke_without_command=True)
@app.command()

Copilot uses AI. Check for mistakes.
cli/test_cli.py Outdated
Comment on lines +65 to +68
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
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These assertions expect strings without trailing periods, but list.py currently outputs periods for ls, cd, and pwd; the test will fail. Align either the test expectations (add periods) or the list.py literals (remove periods) consistently across all entries.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +10
"ls - List directory contents.",
"cd - Change directory.",
"pwd - Print working directory.",
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent punctuation: first three entries end with a period while the last does not, and this inconsistency conflicts with test expectations (which omit periods). Standardize all entries (either all with periods or all without) and sync the tests accordingly.

Suggested change
"ls - List directory contents.",
"cd - Change directory.",
"pwd - Print working directory.",
"ls - List directory contents",
"cd - Change directory",
"pwd - Print working directory",

Copilot uses AI. Check for mistakes.
@devanshsonii
Copy link
Contributor Author

devanshsonii commented Oct 1, 2025

Right, so the issue description specified that

For now, return a static list of a few example commands

I could raise another issue regarding the dynamic list of commands from the chapters and resolve that?
For now I have implemented the changes suggested by copilot.

@bobbyiliev bobbyiliev requested a review from Copilot October 1, 2025 19:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.


app = typer.Typer(help="List the commands available on Linux.")

@app.command()
Copy link

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test invokes cli.py list expecting the command descriptions to print, but this code defines a Typer sub-app with a subcommand also named list; executing cli.py list (without the subcommand) will show the group help, not run the function. To make cli.py list produce the desired output, either move the logic to a top-level command (remove the nested Typer and register the function directly) or change this to @app.callback() so it runs when no subcommand is provided.

Suggested change
@app.command()
@app.callback()

Copilot uses AI. Check for mistakes.
cli/cli.py Outdated
Comment on lines +4 to +11
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")
Copy link

Copilot AI Oct 1, 2025

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")).

Suggested change
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")

Copilot uses AI. Check for mistakes.
cli/cli.py Outdated
Comment on lines +4 to +11
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")
Copy link

Copilot AI Oct 1, 2025

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")).

Suggested change
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")

Copilot uses AI. Check for mistakes.
@bobbyiliev
Copy link
Collaborator

You are right @devanshsonii let's keep the static list for the scope here. If we get the lint to pas we can get this merged right away!

@devanshsonii
Copy link
Contributor Author

Right, I'll get on it.

@devanshsonii
Copy link
Contributor Author

@bobbyiliev should work now.

@bobbyiliev
Copy link
Collaborator

Thanks @devanshsonii the lint CI is passing, the test CI is failing though. If we get that one to pass we can merge it!

@devanshsonii
Copy link
Contributor Author

@bobbyiliev Confirmed that all test cases are passing.

@bobbyiliev bobbyiliev merged commit 9261480 into The-DevOps-Daily:main Oct 2, 2025
2 checks passed
@devanshsonii devanshsonii deleted the list-command branch October 2, 2025 08:42
mt798jx pushed a commit to mt798jx/101-linux-commands that referenced this pull request Oct 2, 2025
* Added the list command.

* copilot suggested fixes.

* lint

* all tests passing

* Update test_cli.py

* Add assertion for command help output in tests

* Update cli.py

---------

Co-authored-by: Bobby Iliev <bobby@bobbyiliev.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 'list' command to show available Linux commands

3 participants