diff options
author | 2021-12-18 23:29:39 -0800 | |
---|---|---|
committer | 2021-12-18 23:29:39 -0800 | |
commit | 4ee8055f17098fdb22f80394b6bedc88cb4d3a59 (patch) | |
tree | 481658567ed9f7436564a29c5f4c04c2835a752b /src | |
parent | 394335fa912d304d8f9dec7bf9019e1559919f93 (diff) | |
download | bun-4ee8055f17098fdb22f80394b6bedc88cb4d3a59.tar.gz bun-4ee8055f17098fdb22f80394b6bedc88cb4d3a59.tar.zst bun-4ee8055f17098fdb22f80394b6bedc88cb4d3a59.zip |
Show help text when no options
Diffstat (limited to 'src')
-rw-r--r-- | src/cli.zig | 5 | ||||
-rw-r--r-- | src/install/install.zig | 71 |
2 files changed, 67 insertions, 9 deletions
diff --git a/src/cli.zig b/src/cli.zig index 5f8d95850..12b110cc8 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -444,7 +444,7 @@ const AutoCommand = struct { const InitCommand = struct { pub fn exec(allocator: *std.mem.Allocator) !void {} }; -const HelpCommand = struct { +pub const HelpCommand = struct { pub fn exec(allocator: *std.mem.Allocator) !void { @setCold(true); execWithReason(allocator, .explicit); @@ -464,7 +464,10 @@ const HelpCommand = struct { "redux", "browserify", "webpack", + "left-pad", + "is-array", "babel-core", + "@parcel/core", }; pub const packages_to_add_filler = [_]string{ diff --git a/src/install/install.zig b/src/install/install.zig index 075a249a0..eb244c028 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -2130,20 +2130,13 @@ pub const Lockfile = struct { } } - pub const Diff = union(Op) { - add: Lockfile.Package.Diff.Entry, - remove: Lockfile.Package.Diff.Entry, - update: struct { in: PackageID, from: Dependency, to: Dependency, from_resolution: PackageID, to_resolution: PackageID }, - - pub const Entry = struct { in: PackageID, dependency: Dependency, resolution: PackageID }; + pub const Diff = struct { pub const Op = enum { add, remove, update, }; - pub const List = std.fifo.LinearFifo(Diff, .Dynamic); - pub const Summary = struct { add: u32 = 0, remove: u32 = 0, @@ -5530,6 +5523,68 @@ pub const PackageManager = struct { var update_requests = try std.BoundedArray(UpdateRequest, 64).init(0); var need_to_get_versions_from_npm = false; + if (manager.options.positionals.len == 1) { + var examples_to_print: [3]string = undefined; + + const off = @intCast(u64, std.time.milliTimestamp()); + + switch (op) { + .update, .add => { + const filler = @import("../cli.zig").HelpCommand.packages_to_add_filler; + + examples_to_print[0] = filler[@intCast(usize, (off) % filler.len)]; + examples_to_print[1] = filler[@intCast(usize, (off + 1) % filler.len)]; + examples_to_print[2] = filler[@intCast(usize, (off + 2) % filler.len)]; + + Output.prettyErrorln( + \\ + \\<r><b>Usage:<r> + \\ + \\ bun add <r><cyan>package-name@version<r> + \\ bun add <r><cyan>package-name<r> + \\ bun add <r><cyan>package-name a-second-package<r> + \\ + \\<r><b>Examples:<r> + \\ + \\ bun add {s} + \\ bun add {s} + \\ bun add {s} + \\ + , .{ examples_to_print[0], examples_to_print[1], examples_to_print[2] }); + Output.flush(); + std.os.exit(0); + }, + .remove => { + const filler = @import("../cli.zig").HelpCommand.packages_to_remove_filler; + + examples_to_print[0] = filler[@intCast(usize, (off) % filler.len)]; + examples_to_print[1] = filler[@intCast(usize, (off + 1) % filler.len)]; + examples_to_print[2] = filler[@intCast(usize, (off + 2) % filler.len)]; + + Output.prettyErrorln( + \\ + \\<r><b>Usage:<r> + \\ + \\ bun remove <r><cyan>package-name<r> + \\ bun remove <r><cyan>package-name a-second-package<r> + \\ + \\<r><b>Examples:<r> + \\ + \\ bun remove {s} {s} + \\ bun remove {s} + \\ + , .{ + examples_to_print[0], + examples_to_print[1], + examples_to_print[2], + }); + Output.flush(); + + std.os.exit(0); + }, + } + } + // first one is always either: // add // remove |