feat: types described, examples of registry

This commit is contained in:
Konrad Geletey 2024-08-21 15:57:38 +03:00
parent f85bd1d03f
commit 7a77314eaf
No known key found for this signature in database
GPG key ID: 862B98E2204889CE
5 changed files with 40 additions and 22 deletions

View file

@ -1,6 +1,6 @@
# Browser command line # Browser command line
The idea is to transform api methods in command line interface The idea is to transform api methods into command line interface
The default shell command, like: The default shell command, like:
@ -24,7 +24,7 @@ wacli ain <tool.dns>
On your website you will need to use `.well-know/wacli.json` file: On your website you will need to use `.well-know/wacli.json` file:
```jsonc ```js
{ {
"api": "<api_url>", "api": "<api_url>",
"bin": { "bin": {
@ -38,7 +38,7 @@ On your website you will need to use `.well-know/wacli.json` file:
"headers": Array<headers>, "headers": Array<headers>,
"aliases": [{ "aliases": [{
"alias": "<short_hand>" | ["short_hand","long_hand"], "alias": "<short_hand>" | ["short_hand","long_hand"],
"type": "path" | "method" | "bin", "type": "path" | "method" | "bin" | "uri",
"description": "description of cli command" "description": "description of cli command"
"content": "<path>" "content": "<path>"
}], }],
@ -152,7 +152,7 @@ You can create registry, by writing to `.well-know/wacli.json` next lines
You can also get help on all api methods using the command You can also get help on all api methods using the command
```sh ```sh
wacli help codeberg.org wacli help git.0ut0f.space
``` ```
Settings format is on Linux by address `$HOME/.config/wacli/wacfg.json` Settings format is on Linux by address `$HOME/.config/wacli/wacfg.json`

8
examples/settings.json Normal file
View file

@ -0,0 +1,8 @@
{
"db_path": "$HOME/.cache/wacrd.db",
"install_dir": "$HOME/.local/bin",
"uri_schemes": {
"registry": "https://wacli.ofs.lol"
}
}

View file

@ -0,0 +1,16 @@
{
"registry": true,
"manifests": {
"forgejo": {
"path": "https://wacli.ofs.lol/registry/forgejo.json"
}
},
"settings": {
"aliases": [{
"type": "uri",
"alias": "registry",
"content": "https://wacli.ofs.lol"
}]
}
}

View file

@ -1,24 +1,18 @@
const std = @import("std"); const std = @import("std");
pub fn main() !void { const OauthFlows = struct { implict: struct { authrizationUrl: []const u8, scopes: std.StringHashMap([]const u8) } };
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
// stdout is for the actual output of your application, for example if you const WellKnownSettings = struct {
// are implementing gzip, then only the compressed bytes should be sent to contentType: []const u8 = "application/json",
// stdout, not any debugging messages. headers: ?[]const ([]const u8),
const stdout_file = std.io.getStdOut().writer(); aliases: ?[]const struct { aliases: union { string: []const u8, array: []const []const u8 }, type: enum { path, method, bin, uri }, description: ?[]const u16, content: ?[]const u8 },
var bw = std.io.bufferedWriter(stdout_file); auth: ?struct { scheme: enum { basic, bearer, oauth2 }, tokenName: ?[]const u8, flows: ?OauthFlows },
const stdout = bw.writer(); };
try stdout.print("Run `zig build test` to run the tests.\n", .{}); const WellKnownSchema = struct { api: ?[]const u8, registry: bool = false, manifests: ?std.StringHashMap(struct { path: []const u8 }), bin: ?[]const std.StringHashMap([]const u8), settings: WellKnownSettings };
try bw.flush(); // don't forget to flush! const UserSettings = struct { db_path: []const u8 = "$HOME/.cache/wacrd.bin", install_dir: []const u8 = "$HOME/.local/bin", uri_shemes: ?std.StringHashMap([]const u8) };
}
test "simple test" { pub fn main() !void {}
var list = std.ArrayList(i32).init(std.testing.allocator);
defer list.deinit(); // try commenting this out and see if zig detects the memory leak! test "spec" {}
try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}