-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdraft.frankie
211 lines (172 loc) · 8.25 KB
/
draft.frankie
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
208
209
210
211
;;?
; @INFO
; This is the syntax draft file for PolarFrankie!
?;;
;; PolarFrankie (command line scripting language)
;; Generate Bash and Batch files from the same source file!
;; This print (echo) style is defined by default in the print library
import "@print" ;; print, Colors
use (System) ;; You can use the "use" keyword to negate the need to use the namespace that a library is under!
;; Note that the "System" namespace is only used by commands that are considered "system commands"
type (print) Error (
;; Prefix text style!
$$prefix-color=Colors:$RED ;; Or "System:Colors:$RED" to call this value!
$$prefix-bold=$TRUE
;; Text style!
$$color=Colors:$WHITE
$$bold=$FALSE
;; New line control!
$$newline-before=$FALSE
$$newline-after=$TRUE
;; Prefix text!
$$prefix="(!) Error: " ;; Default prefix!
$$prefix?="\t " ;; Only when you prefix the Type with a question mark (?) will this assignment will be respected!
;; Cnly the last variable value to be defined in this scope will be respected when duplicates are present!
;; $clean-on-start=$TRUE ;; This will clean up all previous logs before printing
;; $clean-on-end=$TRUE ;; This will clean up logs after printing
)
;; You can make another version of the same type like this!
import "@Default" ;; Notice that libraries that start with capital letters do not include commands! (only components)
type (my-command) MyType base PolarFrankie:Default ( ;; Initialises a type that has all the values of type "Default"!
;; You can modify existing values, or create new ones!
$$new-value="Oh hi!"
)
;; You can define your own element groups/namespaces
group System (
;;
)
;; This spawn style is defined by default in the spawn library
type (spawn) CleanSpawn (
$$clean-output-on-match=$TRUE ;; Cleans up the logs of the spawned command when the output matches the @rule!
$$clean-output-on-end=$FALSE ;; Cleans up the logs of the spawned command when the command is done running!
)
;; You can also import these types from the standard Frankie libraries
import "@spawn" ;; CleanSpawn
import "@print" ;; Error (print)
;; You can also import your own local Frankie files!
import "./my-type.frankie" ;; MyType
print Error "You did something wrong!"
print ?Error "You should be ashamed of yourself!"
;; These two lines will print the following:
;; (!) Error: You did something wrong!
;; You should be ashamed of yourself!
;; If the built-in libraries do not include a command you need to use, you can define it yourself!
;; (all library commands are defined like this!)
;; <command-name> [<short-flat> <long-flag>, <short-flat> <long-flag>, ...] bash (...) batch (...)
command my-command ?*(-f --flag $FLAG) ?*(-x --extra $EXTRA; TEXT|NUMBER $EXTRA-INPUT; TEXT ?$EXTRA-INPUT-2) *(ANY $INPUT-1; TEXT $INPUT-2) bash (
;; You can add documentation to each element of this command using (;;!!) comments!
;;!! |"my-command"| |This command does this!|
;;!! |-f| |This flag does something!|
;;!! |-x| |This flag does something else!|
;;!! |"extra-input"| |This flag input does something extra!|
;; ...
;; These messages will should up for users when they hover the components you're implementing!
;; Do dynamic values are allowed here!
;; Notice that all command elements are constants
;; You must define type/control variables (with their type, no type inference allowed) at the start of this zone!
BOOLEAN $$command-behavior-var
;; You can use the "inject" keyword to inject commands into the final bash/batch files
inject "extra-command ..."
inject "\m" ;; If you want to append other commands to this command, use the escape character "\m" to break commands
;; apart! NEVER use new lines when they are not needed!
;; command
inject "native-command-name"
;; You can use conditional blocks to affect the final output of the command!
if ($$command-behavior-var) (
inject "--do-1"
) else (
inject "--do-2"
)
;; flag
;; (note that any optional element colleciton - ?*(...) - must contain at least one non-optional element!)
if ($FLAG) ( ;; You should always check the status of optional elements before injection!
inject "--native-flag"
)
;; (references to flags always take on the raw text value of the flag!)
;; input
inject $INPUT-1 ;; the order you place this variable in will affect its place in the generated command text!
;; flag
if ($EXTRA) (
inject "--native-extra-flag"
inject $EXTRA-INPUT ;; Usually, if you reference a value as part of a flag, you'd use it within the input zone for
;; that flag!
if ($EXTRA-INPUT-2) (
inject ""
inject $EXTRA-INPUT-2 ;; Notice that this input is optional! Any optional input, just like how flags are
;; optional, must be checked before use!
)
)
if ($EXTRA-INPUT-2) (
inject $EXTRA-INPUT ;; You can check the status of these elements more than once!
)
;; You can also change the final script output depending on the type of the input!
if ($EXTRA-INPUT instance-of NUMBER) (
inject "-some-custom-int-flag"
)else if ($EXTRA-INPUT instance-of TEXT) (
inject "-some-custom-text-flag"
)
;; custom input
inject "-input" ;; You can even add extra text to the final output like this
inject $INPUT-2
) batch (
;; command
inject "./command2" ;; You can also use local native binaries/files as commands!
;; flag
if ($FLAG) (
inject "--win-flag"
)
;; flag
if ($EXTRA) (
inject $INPUT-1 ;; If you reference a value in an argument's scope, this means this value will be included in the
;; final command text only if the argument is present!
)
;; input
inject $INPUT-1 ;; You can even have one input value repeate!
inject $INPUT-2
) default DefaultStyle
;; You can define output match rules!
;; (rule functions can only return TRUE or FALSE)
rule @@rule-function (
;; Do all the minipulation
return $TRUE ;; if the final output is valid, return TRUE! (this is a success)
)
;; You can spawn child processes, and check their output!
import "@extra.npm" ;; this command uses the NodeJS namespace! (npm, Npm)
spawn CleanSpawn #( ;; You can capture the final string value of a command like this!
NodeJS:npm -d --global NodeJS:Npm:$INSTALL
;; In this npm command, NodeJS:Npm:$INSTALL is just a variable that holds the string "install"!
) follow @@rule-function match ( ;; If you fail to handle at least one of these match cases, the build will fail!
print Error "Failed to install NPM dependencies!"
end ;; Safely ends the script execution!
) mismatch (
print Error "Installed NPM dependencies successfully!"
end ;; Safely ends the script execution!
)
;; Make sure the function's output is as expected!
;; There are six data types!
NUMBER ;; Numbers
48324 .4324 2342342.
BOOLEAN ;; Booleans (true/false)
$TRUE $FALSE
TEXT ;; Text (chars, strings, etc.)
"dasdas"
COMMAND ;; Final text generated from commands!
#(my-command)
ANY ;; Any value! (used when not sure of the type of the variable!)
NONE ;; Used for functions to indicate that they do not return a value!
;; If you do not append variables with types on definition, the type of the variable
;; will be inferred! (If no type can be inferred, the type ANY will be assigned to said variable)
;; functions!
function @my-function (NUMBER $input) NUMBER ( ;; If you choose to not specify a return type, the new inferred return type would be NONE!
return $input ;; This function returns a number!
)
@my-function 1 ;; this is how you call this function!
NUMBER $val = $(@my-function 1) ;; This is how capture the value returned by the functions like this!
;; $() - used to capture command output values inside a zone
;; #() - used to capture final bash/batch code in TEXT format
;; *() - used to group command definition elements
;; () - used to group commands/elements! (doesn't end with new lines)
;; New lines are important! They mark the end of a command!
;; You can also end commands with a semicolon to start another command in the same line!
;; You can mix strings this way
"$var-1, $var-2, and $VAR-3! You can escape \$variables too!"