-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor main, bump version, added a test
- Loading branch information
Showing
4 changed files
with
27 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
import subprocess | ||
import sys | ||
|
||
def main(): | ||
if len(sys.argv) < 2 or sys.argv[1] in ['-h', '--help']: | ||
print("Usage: manwrapper <topic>") | ||
print("Please provide a topic for the manual.") | ||
sys.exit(1) | ||
|
||
manTopic = sys.argv[1] | ||
|
||
cmd = ['man', '-P', 'cat', manTopic] | ||
|
||
def get_man_page(topic): | ||
cmd = ['man', '-P', 'cat', topic] | ||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
stdout, stderr = p.communicate() | ||
|
||
encoding = sys.getdefaultencoding() | ||
|
||
if stdout: | ||
print(stdout.decode(encoding)) | ||
return stdout.decode(encoding) | ||
if stderr: | ||
print("Error:", stderr.decode(encoding)) | ||
return "Error: " + stderr.decode(encoding) | ||
|
||
def main(): | ||
if len(sys.argv) < 2 or sys.argv[1] in ['-h', '--help']: | ||
print("Usage: manwrapper <topic>") | ||
print("Please provide a topic for the manual.") | ||
sys.exit(1) | ||
|
||
manTopic = sys.argv[1] | ||
output = get_man_page(manTopic) | ||
print(output) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# test_manwrapper.py | ||
|
||
from manwrapper.main import get_man_page | ||
|
||
def test_get_man_page(): | ||
# Test a known command | ||
result = get_man_page('ls') | ||
assert "list directory contents" in result | ||
|
||
# Test an unknown command | ||
result = get_man_page('nonexistentcommand') | ||
assert "Error:" in result |