forked from LyonSyonII/run
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runfile.run
executable file
·125 lines (109 loc) · 3.84 KB
/
runfile.run
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
/// The default command gets executed when the runfile is called without arguments
cmd default() {
# 'doc' is a special variable that contains the whole documentation of the runfile
echo -n "$doc";
}
// You can declare constants and use them in any command
const constant = Constantinople
// Constants can contain any character (even spaces)
const constant_with_spaces = Constantinople is a nice city, I'd like to visit it one day
// If you want to preserve prefix whitespaces, you have to put the value between quotes
// Either double or single quotes can be used
const whitespace = " \t "
// Use '$(...)' to evaluate a math expression
const math = $(1 + 2 * 3 / 4)
/// Command that uses constants
cmd constants() {
echo constant = $constant;
echo "constant_with_spaces = $constant_with_spaces";
echo 'whitespace = "$whitespace"';
echo '1 + 2 * 3 / 4 = $math';
}
// Define an argument for a command by writing its name between the parentheses
// Use it in the command with the syntax: '$argument'
/// Shell command
sh cmd shell (name) {
# Variable interpolation is done in all languages with $argument
echo Hello $name from the Shell!
}
// The language of a command can be specified by writing its name before 'cmd'
// If no language is specified, the command will be executed in the default shell
/// Bash command
bash cmd bash(name) {
echo "Hello $name from Bash!";
}
// 'cmd' can be omitted if the language is specified
// Variables are replaced with their value before the command is executed,
// so if you want to use one as a String, you have to put it between quotes
/// Python command
py python(name) {
print("Hello $name from Python!")
}
// Any code is valid in the command's body as long as it's valid in the command's language
/// Javascript command
js cmd javascript(name) {
function greet() {
console.log("Hello $name from Javascript!");
}
greet();
}
// Not only interpreted languages are supported, you can also use compiled languages
// These get compiled when the specific command is called for the first time
/// Rust command
rs cmd rust(name) {
println!("Hello $name from Rust!");
}
// C needs you to define the main function
// It's not done automatically because you might want to define other functions
/// C command
c cmd c(name) {
#include <stdio.h>
int main() {
printf("Hello $name from C!\n");
}
}
// The same happens with C++
/// C++ command
c++ cmd cpp(name) {
#include <iostream>
int main() {
std::cout << "Hello $name from C++!" << std::endl;
}
}
c# cmd csharp(name) {
Console.WriteLine("Hello $name from C#!");
}
// Multiple arguments are separated by spaces
// All arguments are positional and required
/// Command with multiple arguments
cmd args(name age) {
echo "Hello $name, you are $age years old."
}
// You can read other arguments from the environment (argv in C)
/// Try calling me with more than one argument!
rs cmd extra-args(first) {
println!("The first explicit argument is $first");
println!("The other ones are: {:?}", std::env::args().skip(1).collect::<Vec<_>>());
}
// You can define subcommands with the 'sub' keyword
// Subcommands can be called with the syntax: 'run subcommand'
// Use 'run subcommand --help' to see the subcommand's documentation
/// I'm a subcommand!
sub subcommand {
// Subcommands can have default commands too
cmd default() {
echo "Hello, I'm a Subcommand!"
}
}
// You can include other files with the 'in' keyword and the path to the file
// The path is relative to the current file and can contain any character (even spaces)
in ./included command.run
// Even subcommands can be included
in ./included-subcommand.run
// You can also include files in a subcommand
// The included commands/subcommands will only be available in the subcommand
/// This is a subcommand with included commands
sub sub-with-included {
in ./included command.run
in ./included-subcommand.run
}