Space code; add comments
This commit is contained in:
parent
f99e5c9b00
commit
e4193a3d1e
25
src/jprog.jl
25
src/jprog.jl
@ -19,9 +19,12 @@
|
|||||||
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
## along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
##
|
##
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import LibGit2
|
import LibGit2
|
||||||
|
|
||||||
DEBUG = false # enable for verbose messages
|
DEBUG = false # enable for verbose messages
|
||||||
|
|
||||||
|
# Generic directory checking with boolean returns
|
||||||
function check_dir(directory)
|
function check_dir(directory)
|
||||||
|
|
||||||
if ispath(directory)
|
if ispath(directory)
|
||||||
@ -36,8 +39,11 @@ function check_dir(directory)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generic file checking with boolean returns
|
||||||
function check_file(filePath)
|
function check_file(filePath)
|
||||||
|
|
||||||
if isfile(filePath)
|
if isfile(filePath)
|
||||||
|
|
||||||
if DEBUG == true print("File: ", filePath, " exists\n") end
|
if DEBUG == true print("File: ", filePath, " exists\n") end
|
||||||
return true
|
return true
|
||||||
|
|
||||||
@ -47,18 +53,22 @@ function check_file(filePath)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Somewhat automate creating directories
|
||||||
function create_default_structure(projectDir)
|
function create_default_structure(projectDir)
|
||||||
|
|
||||||
local subDirs = ["src", "lib"]
|
local subDirs = ["src", "lib"]
|
||||||
for dirs in subDirs
|
for dirs in subDirs
|
||||||
|
|
||||||
mkpath("$projectDir/$dirs")
|
mkpath("$projectDir/$dirs")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# check whether projectDir contains /
|
||||||
projectName = occursin(projectDir, "/" )
|
projectName = occursin(projectDir, "/" )
|
||||||
|
|
||||||
if DEBUG == true print(projectName, "\n") end
|
if DEBUG == true print(projectName, "\n") end
|
||||||
|
|
||||||
|
# append name of project to main source file name
|
||||||
projectName = projectDir[projectName+1:length(projectDir)]
|
projectName = projectDir[projectName+1:length(projectDir)]
|
||||||
|
|
||||||
|
|
||||||
@ -67,9 +77,13 @@ function create_default_structure(projectDir)
|
|||||||
touch("$projectDir/LICENSE")
|
touch("$projectDir/LICENSE")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Establish a Git repository in project root
|
||||||
function git_init(projectPath)
|
function git_init(projectPath)
|
||||||
LibGit2.init("$projectPath", false) # Initialize git repository
|
|
||||||
|
LibGit2.init("$projectPath", false)
|
||||||
|
|
||||||
if check_dir("$projectPath/.git") != true
|
if check_dir("$projectPath/.git") != true
|
||||||
|
|
||||||
print("Failed to initialize git repository in: ", pwd(), "/$projectPath\n")
|
print("Failed to initialize git repository in: ", pwd(), "/$projectPath\n")
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -77,17 +91,20 @@ function git_init(projectPath)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Print a list of supported commands
|
||||||
function help()
|
function help()
|
||||||
print("\n", "useage: jprog init <project name>", "\n", "\n")
|
print("\n", "useage: jprog init <project name>", "\n", "\n")
|
||||||
|
|
||||||
print("init Create a new project\n")
|
print("init Create a new project\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get version information for this program
|
||||||
function version()
|
function version()
|
||||||
|
|
||||||
print("\n", "Version 1\n\n")
|
print("\n", "Version 1\n\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Take arguments from the shell and process them
|
||||||
function main()
|
function main()
|
||||||
local projectName = ARGS[2]
|
local projectName = ARGS[2]
|
||||||
|
|
||||||
@ -96,12 +113,16 @@ function main()
|
|||||||
if DEBUG == true print("ARGS Count: ", length(ARGS), "\n") end
|
if DEBUG == true print("ARGS Count: ", length(ARGS), "\n") end
|
||||||
|
|
||||||
if check_dir(projectName) == true
|
if check_dir(projectName) == true
|
||||||
|
|
||||||
if DEBUG == true print("Dir exists") end
|
if DEBUG == true print("Dir exists") end
|
||||||
|
|
||||||
else
|
else
|
||||||
create_default_structure(projectName)
|
create_default_structure(projectName)
|
||||||
|
|
||||||
if check_dir(projectName) == true
|
if check_dir(projectName) == true
|
||||||
|
|
||||||
print("Project: '", projectName, "' was successfully created in: ", pwd(), "/$projectName\n")
|
print("Project: '", projectName, "' was successfully created in: ", pwd(), "/$projectName\n")
|
||||||
|
|
||||||
git_init("$projectName")
|
git_init("$projectName")
|
||||||
else
|
else
|
||||||
print("The directory: '", projectName, "' could not be created\n")
|
print("The directory: '", projectName, "' could not be created\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user