Skip to content

Commit e0ea5c8

Browse files
committed
Add initial amount of flags
1 parent 9b1ca0a commit e0ea5c8

File tree

2 files changed

+140
-5
lines changed

2 files changed

+140
-5
lines changed

runic.odin

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ along with runic. If not, see <http://www.gnu.org/licenses/>.
1818
package main
1919

2020
import ccdg "c/codegen"
21+
import "core:flags"
2122
import "core:fmt"
2223
import "core:os"
2324
import "core:path/filepath"
@@ -42,13 +43,72 @@ main :: proc() {
4243
defer free_all(context.temp_allocator)
4344
defer free_all(errors.error_allocator)
4445

45-
rune_file_name := "./rune.yml"
46-
host_plat := runic.platform_from_host()
46+
args: struct {
47+
version:
48+
bool `args:"name=version" usage:"Print version and license information"`,
49+
credits:
50+
bool `args:"name=credits" usage:"Print credits to dependencies"`,
51+
rune_file_name:
52+
string `args:"pos=0,name=rune" usage:"The rune configuration file to load"`,
53+
}
54+
55+
if flags_err := flags.parse(&args, os.args[1:], .Unix); flags_err != nil {
56+
switch e in flags_err {
57+
case flags.Parse_Error:
58+
fmt.eprintfln("{}: {}", e.reason, e.message)
59+
os.exit(1)
60+
case flags.Open_File_Error:
61+
fmt.eprintfln("open file \"{}\": {}", e.filename, e.errno)
62+
os.exit(1)
63+
case flags.Help_Request:
64+
flags.write_usage(
65+
os.stream_from_handle(os.stderr),
66+
any(args).id,
67+
os.args[0],
68+
.Unix,
69+
)
70+
os.exit(0)
71+
case flags.Validation_Error:
72+
fmt.eprintfln("validate flags: {}", e.message)
73+
os.exit(1)
74+
}
75+
76+
panic("unreachable")
77+
}
78+
79+
if args.version {
80+
print_version()
81+
os.exit(0)
82+
} else if args.credits {
83+
print_credits()
84+
os.exit(0)
85+
}
4786

48-
if len(os.args) > 1 {
49-
rune_file_name = os.args[1]
87+
rune_file_name := args.rune_file_name
88+
if len(rune_file_name) == 0 {
89+
canditates := [?]string{"rune.yml", "rune.yaml", "rune.json"}
90+
91+
for c in canditates {
92+
if os.is_file(c) {
93+
rune_file_name = c
94+
}
95+
}
96+
97+
if len(rune_file_name) == 0 {
98+
fmt.eprintfln(
99+
"no rune file has been specified and no rune file has been found in the current working directory\ncandiates are {}",
100+
strings.join(
101+
canditates[:],
102+
", ",
103+
allocator = context.temp_allocator,
104+
),
105+
)
106+
os.exit(1)
107+
}
50108
}
51109

110+
host_plat := runic.platform_from_host()
111+
52112
if !filepath.is_abs(rune_file_name) {
53113
cwd := os.get_current_directory()
54114
defer delete(cwd)
@@ -468,4 +528,3 @@ main :: proc() {
468528
}
469529
}
470530
}
471-

version.odin

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
This file is part of runic.
3+
4+
Runic is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License version 2
6+
as published by the Free Software Foundation.
7+
8+
Runic is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with runic. If not, see <http://www.gnu.org/licenses/>.
15+
16+
*/
17+
18+
package main
19+
20+
import "core:fmt"
21+
22+
VERSION_MAJOR :: 0
23+
VERSION_MINOR :: 6
24+
25+
print_version :: #force_inline proc() {
26+
fmt.printfln(
27+
`runic {}.{}
28+
Runic is free software: you can redistribute it and/or modify
29+
it under the terms of the GNU General Public License version 2
30+
as published by the Free Software Foundation.
31+
32+
Runic is distributed in the hope that it will be useful,
33+
but WITHOUT ANY WARRANTY; without even the implied warranty of
34+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35+
GNU General Public License for more details.`,
36+
VERSION_MAJOR,
37+
VERSION_MINOR,
38+
)
39+
}
40+
41+
print_credits :: #force_inline proc() {
42+
fmt.println(
43+
`Runic was able to be made thanks to other free and open source software:
44+
45+
--------------- libclang ------------------
46+
Part of the LLVM Project, under the Apache License v2.0 with LLVM
47+
Exceptions.
48+
See https://llvm.org/LICENSE.txt for license information.
49+
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
50+
--------------- libclang ------------------
51+
52+
--------------- libyaml -------------------
53+
Copyright (c) 2017-2020 Ingy döt Net
54+
Copyright (c) 2006-2016 Kirill Simonov
55+
56+
Permission is hereby granted, free of charge, to any person obtaining a copy of
57+
this software and associated documentation files (the "Software"), to deal in
58+
the Software without restriction, including without limitation the rights to
59+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
60+
of the Software, and to permit persons to whom the Software is furnished to do
61+
so, subject to the following conditions:
62+
63+
The above copyright notice and this permission notice shall be included in all
64+
copies or substantial portions of the Software.
65+
66+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
67+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
68+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
69+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
70+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
71+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
72+
SOFTWARE.
73+
--------------- libyaml -------------------
74+
`,
75+
)
76+
}

0 commit comments

Comments
 (0)