-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from jetzig-framework/cli-update
Add update command to CLI tool
- Loading branch information
Showing
4 changed files
with
165 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const std = @import("std"); | ||
const args = @import("args"); | ||
const util = @import("../util.zig"); | ||
|
||
/// Command line options for the `update` command. | ||
pub const Options = struct { | ||
pub const meta = .{ | ||
.usage_summary = "[NAME=jetzig]", | ||
.full_text = | ||
\\Updates the current project to the latest version of Jetzig. | ||
\\ | ||
\\Optionally pass a positional argument to save the dependency to `build.zig.zon` with an | ||
\\alternative name. | ||
\\ | ||
\\Equivalent to running `zig fetch --save=jetzig https://github.com/jetzig-framework/jetzig/archive/<latest-commit>.tar.gz` | ||
\\ | ||
\\Example: | ||
\\ | ||
\\ jetzig update | ||
\\ jetzig update web | ||
, | ||
.option_docs = .{ | ||
.path = "Set the output path relative to the current directory (default: current directory)", | ||
}, | ||
}; | ||
}; | ||
|
||
/// Run the `jetzig update` command. | ||
pub fn run( | ||
allocator: std.mem.Allocator, | ||
options: Options, | ||
writer: anytype, | ||
positionals: [][]const u8, | ||
other_options: struct { help: bool }, | ||
) !void { | ||
_ = options; | ||
if (other_options.help) { | ||
try args.printHelp(Options, "jetzig update", writer); | ||
return; | ||
} | ||
|
||
if (positionals.len > 1) { | ||
std.debug.print("Expected at most 1 positional argument, found {}\n", .{positionals.len}); | ||
return error.JetzigCommandError; | ||
} | ||
|
||
const name = if (positionals.len > 0) positionals[0] else "jetzig"; | ||
|
||
const github_url = try util.githubUrl(allocator); | ||
defer allocator.free(github_url); | ||
|
||
const save_arg = try std.mem.concat(allocator, u8, &[_][]const u8{ "--save=", name }); | ||
defer allocator.free(save_arg); | ||
|
||
var cwd = try util.detectJetzigProjectDir(); | ||
defer cwd.close(); | ||
|
||
const realpath = try std.fs.realpathAlloc(allocator, "."); | ||
defer allocator.free(realpath); | ||
|
||
try util.runCommand(allocator, realpath, &[_][]const u8{ | ||
"zig", | ||
"fetch", | ||
save_arg, | ||
github_url, | ||
}); | ||
|
||
std.debug.print( | ||
\\Update complete. | ||
\\ | ||
, .{}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters