move main functions to separate file
This commit is contained in:
parent
5cee4ae3dc
commit
8ea5db169a
95
lib/libjprog.jl
Normal file
95
lib/libjprog.jl
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
module LibJprog
|
||||||
|
|
||||||
|
using LibGit2: init
|
||||||
|
export check_dir,
|
||||||
|
check_file,
|
||||||
|
create_default_structure,
|
||||||
|
git_init,
|
||||||
|
help,
|
||||||
|
version,
|
||||||
|
DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DEBUG = false # enable for verbose messages
|
||||||
|
|
||||||
|
# Generic directory checking with boolean returns
|
||||||
|
function check_dir(directory)
|
||||||
|
|
||||||
|
if ispath(directory)
|
||||||
|
if DEBUG == true print("The directory: ", directory, " already exists\n") end
|
||||||
|
return true
|
||||||
|
|
||||||
|
else
|
||||||
|
if DEBUG == true print("The directory: ", directory, " does not exist\n") end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
else
|
||||||
|
if DEBUG == false print("File: ", filePath, " does not exist\n") end
|
||||||
|
return false
|
||||||
|
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)]
|
||||||
|
|
||||||
|
|
||||||
|
touch("$projectDir/src/$projectName.jl")
|
||||||
|
touch("$projectDir/README.md")
|
||||||
|
touch("$projectDir/LICENSE")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Establish a Git repository in project root
|
||||||
|
function git_init(projectPath)
|
||||||
|
|
||||||
|
init("$projectPath", false)
|
||||||
|
|
||||||
|
if check_dir("$projectPath/.git") != true
|
||||||
|
|
||||||
|
print("Failed to initialize git repository in: ", pwd(), "/$projectPath\n")
|
||||||
|
|
||||||
|
else
|
||||||
|
print("Git repository initialized\n")
|
||||||
|
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
|
||||||
|
end
|
85
src/jprog.jl
85
src/jprog.jl
@ -27,89 +27,8 @@
|
|||||||
##
|
##
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
using LibGit2: init
|
include("../lib/libjprog.jl")
|
||||||
|
using Main.LibJprog
|
||||||
DEBUG = false # enable for verbose messages
|
|
||||||
|
|
||||||
# Generic directory checking with boolean returns
|
|
||||||
function check_dir(directory)
|
|
||||||
|
|
||||||
if ispath(directory)
|
|
||||||
if DEBUG == true print("The directory: ", directory, " already exists\n") end
|
|
||||||
return true
|
|
||||||
|
|
||||||
else
|
|
||||||
if DEBUG == true print("The directory: ", directory, " does not exist\n") end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
else
|
|
||||||
if DEBUG == false print("File: ", filePath, " does not exist\n") end
|
|
||||||
return false
|
|
||||||
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)]
|
|
||||||
|
|
||||||
|
|
||||||
touch("$projectDir/src/$projectName.jl")
|
|
||||||
touch("$projectDir/README.md")
|
|
||||||
touch("$projectDir/LICENSE")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Establish a Git repository in project root
|
|
||||||
function git_init(projectPath)
|
|
||||||
|
|
||||||
init("$projectPath", false)
|
|
||||||
|
|
||||||
if check_dir("$projectPath/.git") != true
|
|
||||||
|
|
||||||
print("Failed to initialize git repository in: ", pwd(), "/$projectPath\n")
|
|
||||||
|
|
||||||
else
|
|
||||||
print("Git repository initialized\n")
|
|
||||||
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
|
# Take arguments from the shell and process them
|
||||||
function main()
|
function main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user