Skip to content

Commit

Permalink
Added windows & unix style command line arguments (#1)
Browse files Browse the repository at this point in the history
* Added support for unix and windows style arguments

* Added new command line arguments to README

* Fixed bug where --version and --help would run if more arguments were typed in
  • Loading branch information
IcemanEtika authored Oct 8, 2020
1 parent a95ee7f commit 9a1f59c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ The location to a source file must be supplied.
#### From the command line
```
python gus.py example.html
python gus.py -f example.html or python gus.py --file example.html to check a file
python gus.py -v or python gus.py --version for version info
python gus.py -h or python gus.py --help for help
```
#### From the python shell
```
Expand Down
17 changes: 13 additions & 4 deletions gus.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ def get_help():
help = open('help.txt').read()
print(help)
except:
print("error printing help")
print("error printing help")

if __name__ == "__main__":
if (len(sys.argv)==1):
get_help() # calls for help if no arg provided
if len(sys.argv) == 1:
get_help() # calls for help if no arg provided
elif len(sys.argv) == 2 and str(sys.argv[1])[:1] != "-":
tavo(str(sys.argv[1])) # send command line arg to main function
else:
tavo(str(sys.argv[1])) # send command line arg to main function
if len(sys.argv) == 3 and (sys.argv[1] == "-f" or sys.argv[1] == "--file"):
tavo(str(sys.argv[2])) # send command line arg to main function
elif len(sys.argv) == 2 and (sys.argv[1] == "-v" or sys.argv[1] == "--version"):
print('Get-Url-Status (GUS) Text-As-Visual-Output (TAVO) version 0.1') # print version info
elif len(sys.argv) == 2 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
get_help()
else:
print('invalid argument error') # print if user inputs wrong argument or if there are too many arguments
15 changes: 13 additions & 2 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@
GUS can be used from the command line or python shell
The location to a source file must be supplied.

From the command line:
To check files from the command line:
>>> python gus.py example.txt
or
>>> python gus.py ~/another/file.html
or
>>> python gus.py -f or --file example.txt
or
>>> python gus.py -f or --file ~/another/file.html

To check version information:
>>> python gus.py -v or --version

To get help:
>>> python gus.py -h or --help


From the python shell:
To check files from the python shell:
>>> import gus
>>> gus.tavo("your.filename.here")

Expand Down

0 comments on commit 9a1f59c

Please sign in to comment.