Skip to content

Commit

Permalink
Add version subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
luka-hash authored and kristoff-it committed Jul 23, 2024
1 parent 8aa5f76 commit 124718c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Commands:
fmt Format HTML documents
lsp Start the Super LSP
help Show this menu and exit
version Print Super's version and exit
General Options:
--help, -h Print command specific usage
--help, -h Print command specific usage
```

### Diagnostics
Expand Down Expand Up @@ -59,7 +60,7 @@ Before:

After:
```html
<div>
<div>
<p>Foo</p>
</div>
```
Expand Down Expand Up @@ -87,9 +88,9 @@ Before:

After:
```html
<div
foo="bar"
style="verylongstring"
<div
foo="bar"
style="verylongstring"
>
Foo
</div>
Expand All @@ -99,8 +100,8 @@ After:

Before:
```html
<div
foo="bar"
<div
foo="bar"
style="verylongstring">
Foo
</div>
Expand All @@ -117,7 +118,7 @@ After:
#### VSCode
1. Download a prebuilt version of `superhtml` from the Releases section (or build it yourself).
2. Put `superhtml` in your `PATH`.
3. Install the [Super HTML VSCode extension](https://marketplace.visualstudio.com/items?itemName=LorisCro.super).
3. Install the [Super HTML VSCode extension](https://marketplace.visualstudio.com/items?itemName=LorisCro.super).

#### Helix
Add to your `.config/helix/languages.toml`:
Expand Down Expand Up @@ -147,7 +148,7 @@ Follow your editor specific intructions on how to define a new Language Server f
SuperHTML is also a HTML templating language. More on that soon.

## Contributing
SuperHTML tracks the latest Zig release (0.13.0 at the moment of writing).
SuperHTML tracks the latest Zig release (0.13.0 at the moment of writing).

### Contributing to the HTML paser & LSP
Contributing to the HTML parser and LSP doesn't require you to be familiar with the templating language, basically limiting the scope of what you have to worry about to:
Expand All @@ -163,4 +164,3 @@ You can run `zig test src/html/Ast.zig` to run parser unit tests without needing
Running `zig build` will compile the Super CLI tool, allowing you to also then test the LSP behavior directly from your favorite editor.

The LSP will log in your cache directory so you can `tail -f ~/.cache/super/super.log` to see what happens with the LSP.

12 changes: 10 additions & 2 deletions src/cli.zig
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub const std_options: std.Options = .{
};

var lsp_mode = false;

pub fn panic(
msg: []const u8,
trace: ?*std.builtin.StackTrace,
Expand Down Expand Up @@ -52,7 +53,7 @@ pub fn panic(
std.process.exit(1);
}

pub const Command = enum { fmt, lsp, help };
pub const Command = enum { fmt, lsp, help, version };

pub fn main() !void {
var gpa_impl: std.heap.GeneralPurposeAllocator(.{}) = .{};
Expand All @@ -76,6 +77,7 @@ pub fn main() !void {
.fmt => fmt_exe.run(gpa, args[2..]),
.lsp => lsp_exe.run(gpa, args[2..]),
.help => fatalHelp(),
.version => printVersion(),
} catch |err| fatal("unexpected error: {s}\n", .{@errorName(err)});
}

Expand All @@ -88,15 +90,21 @@ fn oom() noreturn {
fatal("oom\n", .{});
}

fn printVersion() noreturn {
std.debug.print("{s}\n", .{version});
std.process.exit(0);
}

fn fatalHelp() noreturn {
fatal(
\\Usage: super COMMAND [OPTIONS]
\\
\\Commands:
\\Commands:
// \\ check Check HTML documents for syntax errors
\\ fmt Format HTML documents
\\ lsp Start the Super LSP
\\ help Show this menu and exit
\\ version Print Super's version and exit
\\
\\General Options:
\\ --help, -h Print command specific usage
Expand Down

0 comments on commit 124718c

Please sign in to comment.