Skip to content

Commit

Permalink
Fix output name bug
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiLyons authored Mar 19, 2020
1 parent cb8698e commit e15220c
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions ruskko.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import sys, re

output = "index.html" # index.html is default
#---------------------------------------------------------#
# Export files #
#---------------------------------------------------------#
def exportFile(file_contents):
def exportFile(file_contents, output):
export = open(output, "w")
export.write("<!DOCTYPE html>\n") #begins export
export.write("<html>\n")
Expand All @@ -15,19 +14,19 @@ def exportFile(file_contents):
#---------------------------------------------------------#
# Define Ruskko built tags #
#---------------------------------------------------------#
def parser(file):
def parser(file, output):
# Remove comments
for i in file:
if (i.startswith('//')):
file.remove(i)

exportFile(file)
exportFile(file, output)


#---------------------------------------------------------#
# Reading the file #
#---------------------------------------------------------#
def readFile():
def readFile(output):
file = arguments[0]
print("File Input: ", file)
print("File Output: ", output)
Expand All @@ -41,7 +40,7 @@ def readFile():

all_lines = list(filter(None, all_lines))

parser(all_lines)
parser(all_lines, output)


#---------------------------------------------------------#
Expand All @@ -61,26 +60,22 @@ def help():
print("")
exit()

def outputName(name):
global output
output = name + ".html"

def outputFile(new_file):
global output
output = new_file

def fileInput(file):
if (arguments[0] == "-help"):
help()
else:
if (not arguments[0].endswith(".rsko")):
incorrectFile(arguments[0])
else:
readFile()
pass

#---------------------------------------------------------#
# Get/Set arguments such as file and CLI for future use #
#---------------------------------------------------------#
def setOutput(output_name):
output = output_name
readFile(output)

def incorrectUsage(err):
print("Error Detected: ", err, " - Incorrect command usage")
print("Usage: ruskko <filename> [OPTIONS] [COMMAND]")
Expand All @@ -100,16 +95,15 @@ def incorrectFile(file):
# Check Argument Lengths, and run code accordingly
if (args_len == 1):
fileInput(arguments[0])
setOutput("index.html")
elif (args_len == 2):
incorrectUsage("Unused Option")
elif (args_len == 3):
fileInput(arguments[0])
if (arguments[1] == "-o"):
outputName(arguments[2])
readFile()
if (arguments[1] == "-o"):
setOutput(arguments[2] + ".html")
elif(arguments[1] == "-of"):
outputFile(arguments[2])
readFile()
setOutput(arguments[2])
elif (args_len == 0):
incorrectUsage("No File Specified")
else:
Expand Down

0 comments on commit e15220c

Please sign in to comment.