jprog/src/jprog.jl

119 lines
3.2 KiB
Julia
Raw Normal View History

2018-11-07 01:48:01 -07:00
#!/usr/bin/julia
2017-06-19 03:16:32 -07:00
2017-09-04 00:13:05 -07:00
###############################################################################
##
##
2018-11-07 03:03:04 -07:00
## Copyright (C) 2018 Justin Moore
2017-09-04 00:13:05 -07:00
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
##############################################################################
2018-11-07 01:48:01 -07:00
import LibGit2
2017-09-04 00:13:05 -07:00
DEBUG = false # enable for verbose messages
2017-06-19 03:16:32 -07:00
function check_dir(directory)
if ispath(directory)
2017-09-04 00:13:05 -07:00
if DEBUG == true print("The directory: ", directory, " already exists\n") end
2017-06-19 03:16:32 -07:00
return true
else
2017-09-04 00:13:05 -07:00
if DEBUG == true print("The directory: ", directory, " does not exist\n") end
2017-06-19 03:16:32 -07:00
return false
end
end
2017-09-04 00:13:05 -07:00
function check_file(filePath)
if isfile(filePath)
if DEBUG == true print("File: ", filePath, " exists\n") end
return true
else
if DEBUG == false print("File: ", filePath, " does not exist\n") end
return false
end
end
2017-06-19 03:16:32 -07:00
function create_default_structure(projectDir)
2018-11-07 04:59:10 -07:00
local subDirs = ["src", "lib"]
2017-06-19 03:16:32 -07:00
for dirs in subDirs
mkpath("$projectDir/$dirs")
end
2018-11-07 01:48:01 -07:00
projectName = occursin(projectDir, "/" )
2017-09-04 00:13:05 -07:00
if DEBUG == true print(projectName, "\n") end
projectName = projectDir[projectName+1:length(projectDir)]
touch("$projectDir/src/$projectName.jl")
touch("$projectDir/README.md")
touch("$projectDir/LICENSE")
2017-06-19 03:16:32 -07:00
end
2017-09-04 00:13:05 -07:00
function git_init(projectPath)
LibGit2.init("$projectPath", false) # Initialize git repository
2018-11-07 04:59:10 -07:00
if check_dir("$projectPath/.git") != true
print("Failed to initialize git repository in: ", pwd(), "/$projectPath\n")
2018-11-07 04:59:10 -07:00
else
print("Git repository initialized\n")
2017-09-04 00:13:05 -07:00
end
end
2017-06-19 03:16:32 -07:00
function help()
2017-09-04 00:13:05 -07:00
print("\n", "useage: jprog init <project name>", "\n", "\n")
print("init Create a new project\n")
2017-06-19 03:16:32 -07:00
end
2018-11-07 02:35:39 -07:00
function version()
print("\n", "Version 1\n\n")
end
2017-06-19 03:16:32 -07:00
function main()
2018-11-07 04:59:10 -07:00
local projectName = ARGS[2]
2017-06-19 03:16:32 -07:00
if (length(ARGS) == 2 && ARGS[1] == "init")
2017-09-04 00:13:05 -07:00
if DEBUG == true print("ARGS Count: ", length(ARGS), "\n") end
2017-06-19 03:16:32 -07:00
2018-11-07 04:59:10 -07:00
if check_dir(projectName) == true
2017-09-04 00:13:05 -07:00
if DEBUG == true print("Dir exists") end
2017-06-19 03:16:32 -07:00
else
2018-11-07 04:59:10 -07:00
create_default_structure(projectName)
if check_dir(projectName) == true
print("Project: '", projectName, "' was successfully created in: ", pwd(), "/$projectName\n")
git_init("$projectName")
2017-06-19 03:16:32 -07:00
else
2018-11-07 04:59:10 -07:00
print("The directory: '", projectName, "' could not be created\n")
2017-06-19 03:16:32 -07:00
end
end
2018-11-07 02:35:39 -07:00
elseif (length(ARGS) == 1 && ARGS[1] == "-v")
version()
2017-06-19 03:16:32 -07:00
else
help()
end
end
2017-09-04 00:13:05 -07:00
main()