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