jprog/lib/libjprog.jl

95 lines
2.3 KiB
Julia
Raw Normal View History

2018-11-27 02:03:07 -07:00
module LibJprog
2019-02-08 22:20:58 -07:00
using LibGit2:init
2018-11-27 02:03:07 -07:00
export check_dir,
check_file,
create_default_structure,
git_init,
help,
version,
DEBUG
2018-12-04 02:48:54 -07:00
DEBUG = false # enable for verbose messages
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
# Generic directory checking with boolean returns
function check_dir(directory)
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
if ispath(directory)
if DEBUG == true print("The directory: ", directory, " already exists\n") end
return true
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
else
if DEBUG == true print("The directory: ", directory, " does not exist\n") end
return false
end
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
end
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
# Generic file checking with boolean returns
function check_file(filePath)
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
if isfile(filePath)
if DEBUG == true print("File: ", filePath, " exists\n") end
return true
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
else
if DEBUG == false print("File: ", filePath, " does not exist\n") end
return false
end
2018-11-27 02:03:07 -07:00
end
2018-12-04 02:48:54 -07:00
# Somewhat automate creating directories
function create_default_structure(projectDir)
local subDirs = ["src", "lib"]
for dirs in subDirs
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
mkpath("$projectDir/$dirs")
end
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
# check whether projectDir contains /
projectName = occursin(projectDir, "/" )
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
if DEBUG == true print(projectName, "\n") end
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
# append name of project to main source file name
projectName = projectDir[projectName+1:length(projectDir)]
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
touch("$projectDir/src/$projectName.jl")
touch("$projectDir/README.md")
touch("$projectDir/LICENSE")
end
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
# Establish a Git repository in project root
function git_init(projectPath)
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
init("$projectPath", false)
if check_dir("$projectPath/.git") != true
print("Failed to initialize git repository in: ", pwd(), "/$projectPath\n")
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
else
print("Git repository initialized\n")
end
2018-11-27 02:03:07 -07:00
end
2018-12-04 02:48:54 -07:00
# 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
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
# Get version information for this program
function version()
2018-11-27 02:03:07 -07:00
2018-12-04 02:48:54 -07:00
print("\n", "Version 1\n\n")
end
2019-02-08 22:20:58 -07:00
end