Skip to content

Commit

Permalink
Added About, help, Version flags in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
garvit-joshi committed May 25, 2021
1 parent 77e7f19 commit 0ff09ee
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 65 deletions.
20 changes: 10 additions & 10 deletions kompiler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright (c) 2021 Garvit Joshi <garvitjoshi9@gmail.com>


# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Copyright (c) 2021 Garvit Joshi <garvitjoshi9@gmail.com>


# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
129 changes: 76 additions & 53 deletions kompiler/__main__.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,76 @@
# Copyright (c) 2021 Garvit Joshi <garvitjoshi9@gmail.com>


# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


import sys
from os import system, path, name
from time import sleep, ctime


def clear_screen():
system('cls' if name == 'nt' else 'clear')


def main():
argv = sys.argv
args_len = len(argv)
if args_len == 1:
print("Please give a file name to watch")
sys.exit()
elif args_len == 2:
command = "g++ " + argv[1]
else:
command = "g++ " + (" ".join(argv[2:]))
print("Command used for compiling:", command)
try:
timer = ctime(path.getmtime(argv[1]))
except FileNotFoundError:
print("File:", argv[1], "Not Found")
sys.exit()
last_timer = 0
system(command)
while True:
if last_timer == 0:
last_timer = timer
timer = ctime(path.getmtime(argv[1]))
if timer != last_timer:
clear_screen()
system(command)
last_timer = timer
timer = ctime(path.getmtime(argv[1]))
sleep(1)


if __name__ == "__main__":
sys.exit(main())
# Copyright (c) 2021 Garvit Joshi <garvitjoshi9@gmail.com>


# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


import sys
from os import system, path, name
from time import sleep, ctime
import kompiler.constants as C


def clear_screen():
system('cls' if name == 'nt' else 'clear')


def version():
print(C.VERSION)


def about():
print(C.ABOUT)


def help():
print(C.HELP)


def main():
argv = sys.argv
args_len = len(argv)
if args_len == 1:
print("Please give a file name to watch")
help()
sys.exit()
elif args_len == 2:
if argv[1] in ("--version", "-v"):
version()
sys.exit()
elif argv[1] in ("--help", "-h"):
help()
sys.exit()
elif argv[1] in ("--about", "-a"):
about()
sys.exit()
command = "g++ " + argv[1]
else:
command = "g++ " + (" ".join(argv[2:]))
print("Command used for compiling:", command)
try:
timer = ctime(path.getmtime(argv[1]))
except FileNotFoundError:
print("File:", argv[1], "Not Found")
sys.exit()
last_timer = 0
system(command)
while True:
if last_timer == 0:
last_timer = timer
timer = ctime(path.getmtime(argv[1]))
if timer != last_timer:
clear_screen()
system(command)
last_timer = timer
timer = ctime(path.getmtime(argv[1]))
sleep(1)


if __name__ == "__main__":
sys.exit(main())
19 changes: 19 additions & 0 deletions kompiler/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
VERSION_NO = "0.4.0"

VERSION = "Kompiler: v"+VERSION_NO

ABOUT = """
Kompiler: A package for auto compiling C++ files as soon as they are saved.\n
Source Code: https://github.com/garvit-joshi/kompiler/
pip: https://pypi.org/project/kompiler/
Made by Garvit Joshi https://github.com/garvit-joshi
"""

HELP = """
Usage: kompiler [File.cpp] [COMMAND...]
eg:
❯ kompiler hello.cpp
Command used for compiling: g++ hello.cpp\n
❯ kompiler hello.cpp -std=c++11 -O2 -Wall hello.cpp -o hello
Command used for compiling: g++ -std=c++11 -O2 -Wall hello.cpp -o hello\n
"""
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
requires = [
"setuptools>=56",
"wheel>=0.36",
"pip>=21"
"pip>=21.1.2"
]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="kompiler",
version="v0.2.0",
version="0.4.0",
author="Garvit Joshi",
author_email="garvitjoshi9@gmail.com",
description="A package for auto compiling C++ files as soon as they are saved.",
Expand Down

0 comments on commit 0ff09ee

Please sign in to comment.