-
Notifications
You must be signed in to change notification settings - Fork 0
/
l3g.cr
207 lines (170 loc) · 5.32 KB
/
l3g.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
require "option_parser"
# --------------------------- Defaults ---------------------------
# These are the default values used by the parser
path = "."
_write_license = false
_commit = false
_topush = false
_debug = false
# --------------------------- Builtin functions ---------------------------
# Prints out text with cool dashes on the side
def pretty_puts(text : String)
width = 10
puts "-" * width + " #{text} " + "-" * width
end
# Commits the path it's given
def commit(_path : String)
system "git add #{_path}"
system "git commit -m \"Commited auto-magically because l3gacy was too lazy to actually write a commit message for this.\""
pretty_puts "Commited #{_path} to the local repo"
end
def write_license(_path : String)
# license is set here
license = "This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>"
File.write _path + "/UNLICENSE", license
pretty_puts "Written license to #{_path}"
end
# Determine if file is in path
def in_path(file : String, path : String) : Bool
# Creates a path item with the supplied path
path = Dir.new path
# Flags if the file has been found
_found = false
path.each do |itered|
# If the file is the one were looking for, mark it as found
if itered == file
_found = true
end
end
# Return that
_found
end
def init
pretty_puts "Create git repo"
system "git init"
write_license "."
pretty_puts "Commiting"
commit "."
end
def install(path : String)
# Test for the binary in the local directory
if in_path "l3g", path
puts "The binary has been found! Commencing install process."
pretty_puts "Moving Binary to /usr/bin/"
puts "You may need to put in your password to move the file"
# Just run a command
system "sudo mv ./l3g /usr/bin/"
puts "Move has been attempted! The l3g command should work now."
else
STDERR.puts "ERROR: The l3g binary is not avalible in the current directory"
exit 1
end
end
def create_project(_type : String)
case _type
# When NextJs is the type of the project, this code runs
when "next"
pretty_puts "Using yarn"
system "yarn create next-app ."
init
end
end
# --------------------------- Parser for the cli ---------------------------
OptionParser.parse do |parser|
parser.banner = "L3gacy's toolkit"
parser.on "init", "initialize a new project" do
init
_write_license = true
end
parser.on "nextjs", "Create a new nextjs project" do
create_project "next"
end
# license generation
parser.on "license", "Generate license" do
# Write license to file
_write_license = true
# no exit, just continue
end
parser.on "git-config", "configure git with my info" do
# configures git with my info
system "git config --global user.email \"[email protected]\""
system "git config --global user.name \"l3gacyb3ta\""
pretty_puts "git configured"
end
# Installs the binary to /usr/bin
parser.on "install", "Install l3g to the user dir" do
install "."
end
# Version info
parser.on "-v", "--version", "Show version" do
puts "version 0.3"
exit
end
# Help
parser.on "-h", "--help", "Show help" do
puts parser
exit
end
# sets up path
parser.on "-d PATH", "--dir=PATH", "Specify path for command, defaults to ." do |_path|
path = _path
end
parser.on "-c", "--commit", "Commit to git repo" do
_commit = true
end
parser.on "-p", "--push", "Turns on pushing after actions" do
_topush = true
end
parser.on "-d", "--debug", "Does whatever I'm needing to debug" do
_debug = true
end
# Error handling
parser.invalid_option do |flag|
STDERR.puts "ERROR: #{flag} is not a valid option."
STDERR.puts parser
exit(1)
end
end
# --------------------------- Flag functions ---------------------------
# Debug runs if debug flag is set
if _debug
p! pretty_puts "Nothing here for now!"
end
# If we need to write, then write license
if _write_license
if _commit
write_license "."
commit "UNLICENSE"
else
write_license "."
end
exit
end
# This little block runs if the commit flag is true
if _commit
commit path
end
# This little block runs if the push flag is true
if _topush
system "git push"
pretty_puts "pushed (hopefully)"
end