@pilatos/bitbucket-cli 1.8.2 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +560 -67
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -14337,6 +14337,12 @@ var applyOptions = (object, options = {}) => {
14337
14337
  const colorLevel = stdoutColor ? stdoutColor.level : 0;
14338
14338
  object.level = options.level === undefined ? colorLevel : options.level;
14339
14339
  };
14340
+
14341
+ class Chalk {
14342
+ constructor(options) {
14343
+ return chalkFactory(options);
14344
+ }
14345
+ }
14340
14346
  var chalkFactory = (options) => {
14341
14347
  const chalk = (...strings) => strings.join(" ");
14342
14348
  applyOptions(chalk, options);
@@ -21341,6 +21347,288 @@ class CloneCommand extends BaseCommand {
21341
21347
  }
21342
21348
  }
21343
21349
 
21350
+ // src/services/response-parsers.ts
21351
+ function isRecord(value) {
21352
+ return typeof value === "object" && value !== null;
21353
+ }
21354
+ function getString(value) {
21355
+ return typeof value === "string" ? value : undefined;
21356
+ }
21357
+ function getNumber(value) {
21358
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
21359
+ }
21360
+ function getIterable(value) {
21361
+ if (Array.isArray(value)) {
21362
+ return value;
21363
+ }
21364
+ if (typeof value !== "object" || value === null) {
21365
+ return;
21366
+ }
21367
+ const iterableCandidate = value;
21368
+ const iterator2 = iterableCandidate[Symbol.iterator];
21369
+ return typeof iterator2 === "function" ? value : undefined;
21370
+ }
21371
+ function getValuesIterable(data) {
21372
+ if (isRecord(data) && "values" in data) {
21373
+ return getIterable(data.values);
21374
+ }
21375
+ return getIterable(data);
21376
+ }
21377
+ function mapPaginatedValues(data, mapValue) {
21378
+ const iterableValues = getValuesIterable(data);
21379
+ const values = [];
21380
+ if (iterableValues) {
21381
+ for (const value of iterableValues) {
21382
+ const mappedValue = mapValue(value);
21383
+ if (mappedValue !== undefined) {
21384
+ values.push(mappedValue);
21385
+ }
21386
+ }
21387
+ }
21388
+ const next = isRecord(data) ? getString(data.next) : undefined;
21389
+ return {
21390
+ values,
21391
+ next
21392
+ };
21393
+ }
21394
+ function getCommitFilePath(file) {
21395
+ if (!isRecord(file)) {
21396
+ return;
21397
+ }
21398
+ const path = file.path;
21399
+ return typeof path === "string" && path.length > 0 ? path : undefined;
21400
+ }
21401
+ function parseDiffstatFile(value) {
21402
+ if (!isRecord(value)) {
21403
+ return;
21404
+ }
21405
+ return {
21406
+ path: getCommitFilePath(value.new) ?? getCommitFilePath(value.old) ?? "unknown",
21407
+ additions: getNumber(value.lines_added) ?? 0,
21408
+ deletions: getNumber(value.lines_removed) ?? 0
21409
+ };
21410
+ }
21411
+ function parseActivityUser(value) {
21412
+ if (!isRecord(value)) {
21413
+ return;
21414
+ }
21415
+ const displayName = getString(value.display_name);
21416
+ const username = getString(value.username);
21417
+ const nickname = getString(value.nickname);
21418
+ if (!displayName && !username && !nickname) {
21419
+ return;
21420
+ }
21421
+ return {
21422
+ display_name: displayName,
21423
+ username,
21424
+ nickname
21425
+ };
21426
+ }
21427
+ function parseActivityHash(value) {
21428
+ if (!isRecord(value)) {
21429
+ return;
21430
+ }
21431
+ const hash = getString(value.hash);
21432
+ return hash ? { hash } : undefined;
21433
+ }
21434
+ function parseActivityComment(value) {
21435
+ if (!isRecord(value)) {
21436
+ return;
21437
+ }
21438
+ const id = getNumber(value.id);
21439
+ const raw = getRawContent(value.content);
21440
+ const user = parseActivityUser(value.user);
21441
+ const author = parseActivityUser(value.author);
21442
+ const createdOn = getString(value.created_on);
21443
+ if (id === undefined && raw === undefined && !user && !author && !createdOn) {
21444
+ return;
21445
+ }
21446
+ return {
21447
+ id,
21448
+ content: raw === undefined ? undefined : { raw },
21449
+ user,
21450
+ author,
21451
+ created_on: createdOn
21452
+ };
21453
+ }
21454
+ function parseApproval(value) {
21455
+ if (!isRecord(value)) {
21456
+ return;
21457
+ }
21458
+ const user = parseActivityUser(value.user);
21459
+ const date = getString(value.date);
21460
+ if (!user && !date) {
21461
+ return;
21462
+ }
21463
+ return { user, date };
21464
+ }
21465
+ function parseChangesRequested(value) {
21466
+ if (!isRecord(value)) {
21467
+ return;
21468
+ }
21469
+ const user = parseActivityUser(value.user);
21470
+ const reason = getString(value.reason);
21471
+ const date = getString(value.date);
21472
+ if (!user && !reason && !date) {
21473
+ return;
21474
+ }
21475
+ return {
21476
+ user,
21477
+ reason,
21478
+ date
21479
+ };
21480
+ }
21481
+ function parseMerge(value) {
21482
+ if (!isRecord(value)) {
21483
+ return;
21484
+ }
21485
+ const user = parseActivityUser(value.user);
21486
+ const date = getString(value.date);
21487
+ const commit = parseActivityHash(value.commit);
21488
+ if (!user && !date && !commit) {
21489
+ return;
21490
+ }
21491
+ return {
21492
+ user,
21493
+ date,
21494
+ commit
21495
+ };
21496
+ }
21497
+ function parseDecline(value) {
21498
+ if (!isRecord(value)) {
21499
+ return;
21500
+ }
21501
+ const user = parseActivityUser(value.user);
21502
+ const date = getString(value.date);
21503
+ if (!user && !date) {
21504
+ return;
21505
+ }
21506
+ return { user, date };
21507
+ }
21508
+ function parseCommit(value) {
21509
+ if (!isRecord(value)) {
21510
+ return;
21511
+ }
21512
+ const date = getString(value.date);
21513
+ const hash = getString(value.hash);
21514
+ const author = isRecord(value.author) ? {
21515
+ user: parseActivityUser(value.author.user)
21516
+ } : undefined;
21517
+ if (!date && !hash && !author?.user) {
21518
+ return;
21519
+ }
21520
+ return {
21521
+ date,
21522
+ hash,
21523
+ author
21524
+ };
21525
+ }
21526
+ function parseUpdate(value) {
21527
+ if (!isRecord(value)) {
21528
+ return;
21529
+ }
21530
+ const author = parseActivityUser(value.author);
21531
+ const date = getString(value.date);
21532
+ const title = getString(value.title);
21533
+ const description = getString(value.description);
21534
+ const state = getString(value.state);
21535
+ if (!author && !date && !title && !description && !state) {
21536
+ return;
21537
+ }
21538
+ return {
21539
+ author,
21540
+ date,
21541
+ title,
21542
+ description,
21543
+ state
21544
+ };
21545
+ }
21546
+ function parseActivity(value) {
21547
+ if (!isRecord(value)) {
21548
+ return;
21549
+ }
21550
+ return {
21551
+ type: getString(value.type),
21552
+ comment: parseActivityComment(value.comment),
21553
+ approval: parseApproval(value.approval),
21554
+ changes_requested: parseChangesRequested(value.changes_requested),
21555
+ merge: parseMerge(value.merge),
21556
+ decline: parseDecline(value.decline),
21557
+ commit: parseCommit(value.commit),
21558
+ update: parseUpdate(value.update),
21559
+ user: parseActivityUser(value.user)
21560
+ };
21561
+ }
21562
+ function getLinkHref(links, key) {
21563
+ if (!isRecord(links)) {
21564
+ return;
21565
+ }
21566
+ const link = links[key];
21567
+ if (!isRecord(link)) {
21568
+ return;
21569
+ }
21570
+ return getString(link.href);
21571
+ }
21572
+ function getCloneLinks(links) {
21573
+ if (!isRecord(links)) {
21574
+ return [];
21575
+ }
21576
+ const cloneLinks = getIterable(links.clone);
21577
+ if (!cloneLinks) {
21578
+ return [];
21579
+ }
21580
+ const parsedLinks = [];
21581
+ for (const cloneLink of cloneLinks) {
21582
+ if (!isRecord(cloneLink)) {
21583
+ continue;
21584
+ }
21585
+ const name = getString(cloneLink.name);
21586
+ const href = getString(cloneLink.href);
21587
+ if (name && href) {
21588
+ parsedLinks.push({ name, href });
21589
+ }
21590
+ }
21591
+ return parsedLinks;
21592
+ }
21593
+ function getBranchName(endpoint) {
21594
+ if (!isRecord(endpoint)) {
21595
+ return;
21596
+ }
21597
+ const branch = endpoint.branch;
21598
+ if (!isRecord(branch)) {
21599
+ return;
21600
+ }
21601
+ const name = branch.name;
21602
+ return typeof name === "string" && name.length > 0 ? name : undefined;
21603
+ }
21604
+ function getUserDisplayName(user) {
21605
+ if (!isRecord(user)) {
21606
+ return;
21607
+ }
21608
+ const nickname = getString(user.nickname);
21609
+ if (nickname && nickname.length > 0) {
21610
+ return nickname;
21611
+ }
21612
+ const displayName = getString(user.display_name);
21613
+ if (displayName && displayName.length > 0) {
21614
+ return displayName;
21615
+ }
21616
+ const username = getString(user.username);
21617
+ return username && username.length > 0 ? username : undefined;
21618
+ }
21619
+ function getRawContent(content) {
21620
+ if (!isRecord(content)) {
21621
+ return;
21622
+ }
21623
+ return getString(content.raw);
21624
+ }
21625
+ function parseDiffstatFiles(data) {
21626
+ return Array.from(mapPaginatedValues(data, parseDiffstatFile).values ?? []);
21627
+ }
21628
+ function parsePullrequestActivitiesPage(data) {
21629
+ return mapPaginatedValues(data, parseActivity);
21630
+ }
21631
+
21344
21632
  // src/commands/repo/create.command.ts
21345
21633
  class CreateRepoCommand extends BaseCommand {
21346
21634
  repositoriesApi;
@@ -21379,8 +21667,9 @@ class CreateRepoCommand extends BaseCommand {
21379
21667
  return;
21380
21668
  }
21381
21669
  this.output.success(`Created repository ${repo.full_name}`);
21382
- this.output.text(` ${this.output.dim("URL:")} ${repo.links?.html?.href}`);
21383
- const sshClone = Array.from(repo.links?.clone ?? []).find((c) => c.name === "ssh");
21670
+ const repoUrl = getLinkHref(repo.links, "html") ?? "";
21671
+ this.output.text(` ${this.output.dim("URL:")} ${repoUrl}`);
21672
+ const sshClone = getCloneLinks(repo.links).find((cloneLink) => cloneLink.name === "ssh");
21384
21673
  if (sshClone?.href) {
21385
21674
  this.output.text(` ${this.output.dim("Clone:")} git clone ${sshClone.href}`);
21386
21675
  }
@@ -21553,8 +21842,9 @@ class ViewRepoCommand extends BaseCommand {
21553
21842
  this.output.text(` ${this.output.dim("Created:")} ${this.output.formatDate(repo.created_on ?? "")}`);
21554
21843
  this.output.text(` ${this.output.dim("Updated:")} ${this.output.formatDate(repo.updated_on ?? "")}`);
21555
21844
  this.output.text("");
21556
- this.output.text(` ${this.output.dim("URL:")} ${repo.links?.html?.href}`);
21557
- const sshClone = Array.from(repo.links?.clone ?? []).find((c) => c.name === "ssh");
21845
+ const repoUrl = getLinkHref(repo.links, "html") ?? "";
21846
+ this.output.text(` ${this.output.dim("URL:")} ${repoUrl}`);
21847
+ const sshClone = getCloneLinks(repo.links).find((cloneLink) => cloneLink.name === "ssh");
21558
21848
  if (sshClone?.href) {
21559
21849
  this.output.text(` ${this.output.dim("SSH:")} ${sshClone.href}`);
21560
21850
  }
@@ -22143,7 +22433,7 @@ class CheckoutPRCommand extends BaseCommand {
22143
22433
  pullRequestId: prId
22144
22434
  });
22145
22435
  const pr = prResponse.data;
22146
- const branchName = pr.source?.branch?.name;
22436
+ const branchName = getBranchName(pr.source);
22147
22437
  const localBranchName = `pr-${prId}`;
22148
22438
  if (!branchName) {
22149
22439
  throw new BBError({
@@ -22233,8 +22523,7 @@ class DiffPRCommand extends BaseCommand {
22233
22523
  return response.data;
22234
22524
  },
22235
22525
  shouldInclude: (pullRequest) => {
22236
- const source = pullRequest.source;
22237
- return source?.branch?.name === currentBranch;
22526
+ return getBranchName(pullRequest.source) === currentBranch;
22238
22527
  }
22239
22528
  });
22240
22529
  const pr = matches[0];
@@ -22318,8 +22607,7 @@ class DiffPRCommand extends BaseCommand {
22318
22607
  repoSlug,
22319
22608
  pullRequestId: prId
22320
22609
  });
22321
- const links = prResponse.data.links;
22322
- const htmlUrl = links?.html?.href;
22610
+ const htmlUrl = getLinkHref(prResponse.data.links, "html");
22323
22611
  if (htmlUrl) {
22324
22612
  const normalizedHtmlUrl = htmlUrl.replace(/\/$/, "");
22325
22613
  return `${normalizedHtmlUrl}/diff`;
@@ -22332,15 +22620,7 @@ class DiffPRCommand extends BaseCommand {
22332
22620
  repoSlug,
22333
22621
  pullRequestId: prId
22334
22622
  });
22335
- const diffstat = diffstatResponse.data;
22336
- const files = Array.from(diffstat.values ?? []).map((file) => {
22337
- const path = file.new?.path || file.old?.path || "unknown";
22338
- return {
22339
- path,
22340
- additions: file.lines_added ?? 0,
22341
- deletions: file.lines_removed ?? 0
22342
- };
22343
- });
22623
+ const files = parseDiffstatFiles(diffstatResponse.data);
22344
22624
  const totalAdditions = files.reduce((sum, f) => sum + f.additions, 0);
22345
22625
  const totalDeletions = files.reduce((sum, f) => sum + f.deletions, 0);
22346
22626
  const filesChanged = files.length;
@@ -22378,8 +22658,7 @@ class DiffPRCommand extends BaseCommand {
22378
22658
  repoSlug,
22379
22659
  pullRequestId: prId
22380
22660
  });
22381
- const diffstat = diffstatResponse.data;
22382
- const fileNames = Array.from(diffstat.values ?? []).map((file) => file.new?.path || file.old?.path || "unknown");
22661
+ const fileNames = parseDiffstatFiles(diffstatResponse.data).map((file) => file.path);
22383
22662
  if (useJson) {
22384
22663
  return fileNames;
22385
22664
  }
@@ -22459,7 +22738,7 @@ class ActivityPRCommand extends BaseCommand {
22459
22738
  }, {
22460
22739
  params: { page, pagelen }
22461
22740
  });
22462
- return response.data;
22741
+ return parsePullrequestActivitiesPage(response.data);
22463
22742
  },
22464
22743
  shouldInclude: (activity) => {
22465
22744
  if (filterTypes.length === 0) {
@@ -22468,7 +22747,6 @@ class ActivityPRCommand extends BaseCommand {
22468
22747
  return filterTypes.includes(this.getActivityType(activity));
22469
22748
  }
22470
22749
  });
22471
- const typedActivities = activities;
22472
22750
  if (context.globalOptions.json) {
22473
22751
  this.output.json({
22474
22752
  workspace: repoContext.workspace,
@@ -22477,12 +22755,12 @@ class ActivityPRCommand extends BaseCommand {
22477
22755
  filters: {
22478
22756
  types: filterTypes
22479
22757
  },
22480
- count: typedActivities.length,
22481
- activities: typedActivities
22758
+ count: activities.length,
22759
+ activities
22482
22760
  });
22483
22761
  return;
22484
22762
  }
22485
- if (typedActivities.length === 0) {
22763
+ if (activities.length === 0) {
22486
22764
  if (filterTypes.length > 0) {
22487
22765
  this.output.info("No activity entries matched the requested filter");
22488
22766
  } else {
@@ -22490,7 +22768,7 @@ class ActivityPRCommand extends BaseCommand {
22490
22768
  }
22491
22769
  return;
22492
22770
  }
22493
- const rows = typedActivities.map((activity) => {
22771
+ const rows = activities.map((activity) => {
22494
22772
  const activityType = this.getActivityType(activity);
22495
22773
  return [
22496
22774
  activityType.toUpperCase(),
@@ -22533,10 +22811,7 @@ class ActivityPRCommand extends BaseCommand {
22533
22811
  }
22534
22812
  getActorName(activity) {
22535
22813
  const user = activity.comment?.user ?? activity.comment?.author ?? activity.approval?.user ?? activity.update?.author ?? activity.changes_requested?.user ?? activity.merge?.user ?? activity.decline?.user ?? activity.commit?.author?.user ?? activity.user;
22536
- if (!user) {
22537
- return "Unknown";
22538
- }
22539
- return user.display_name || user.username || "Unknown";
22814
+ return getUserDisplayName(user) ?? "Unknown";
22540
22815
  }
22541
22816
  formatActivityDate(activity) {
22542
22817
  const date = activity.comment?.created_on ?? activity.approval?.date ?? activity.update?.date ?? activity.changes_requested?.date ?? activity.merge?.date ?? activity.decline?.date ?? activity.commit?.date;
@@ -22548,7 +22823,7 @@ class ActivityPRCommand extends BaseCommand {
22548
22823
  buildActivityDetails(activity, type) {
22549
22824
  switch (type) {
22550
22825
  case "comment": {
22551
- const content = activity.comment?.content?.raw ?? "";
22826
+ const content = getRawContent(activity.comment?.content) ?? "";
22552
22827
  const id = activity.comment?.id ? `#${activity.comment.id}` : "";
22553
22828
  const snippet = this.truncate(content, 80);
22554
22829
  return [id, snippet].filter(Boolean).join(" ");
@@ -22728,10 +23003,10 @@ class ListCommentsPRCommand extends BaseCommand {
22728
23003
  return;
22729
23004
  }
22730
23005
  const rows = values.map((comment) => {
22731
- const content = comment.content?.raw ?? "";
23006
+ const content = getRawContent(comment.content) ?? "";
22732
23007
  return [
22733
23008
  comment.id?.toString() ?? "",
22734
- comment.user?.nickname ?? comment.user?.display_name ?? "Unknown",
23009
+ getUserDisplayName(comment.user) ?? "Unknown",
22735
23010
  comment.deleted ? "[deleted]" : options.truncate === false ? content : content.slice(0, 60) + (content.length > 60 ? "..." : ""),
22736
23011
  this.output.formatDate(comment.created_on ?? "")
22737
23012
  ];
@@ -23539,6 +23814,51 @@ function bootstrap(options = {}) {
23539
23814
  return container;
23540
23815
  }
23541
23816
 
23817
+ // src/help-text.ts
23818
+ function createHelpTextBuilder(noColor) {
23819
+ const passthrough = (t) => t;
23820
+ const chalk2 = new Chalk({ level: noColor ? 0 : 1 });
23821
+ const c = noColor ? { bold: passthrough, dim: passthrough, cyan: passthrough } : { bold: chalk2.bold, dim: chalk2.dim, cyan: chalk2.cyan };
23822
+ return function buildHelpText(config) {
23823
+ const sections = [];
23824
+ if (config.examples?.length) {
23825
+ sections.push(c.bold("Examples:"));
23826
+ for (const example of config.examples) {
23827
+ sections.push(` ${c.dim("$")} ${example}`);
23828
+ }
23829
+ }
23830
+ if (config.validValues) {
23831
+ for (const [label, values] of Object.entries(config.validValues)) {
23832
+ if (sections.length)
23833
+ sections.push("");
23834
+ sections.push(c.bold(`${label}:`));
23835
+ sections.push(` ${c.cyan(values.join(", "))}`);
23836
+ }
23837
+ }
23838
+ if (config.defaults) {
23839
+ if (sections.length)
23840
+ sections.push("");
23841
+ sections.push(c.bold("Defaults:"));
23842
+ for (const [key, value] of Object.entries(config.defaults)) {
23843
+ sections.push(` ${c.bold(`--${key}`)} ${c.cyan(value)}`);
23844
+ }
23845
+ }
23846
+ if (config.envVars) {
23847
+ if (sections.length)
23848
+ sections.push("");
23849
+ sections.push(c.bold("Environment variables:"));
23850
+ const maxLen = Math.max(...Object.keys(config.envVars).map((k) => k.length));
23851
+ for (const [name, desc] of Object.entries(config.envVars)) {
23852
+ sections.push(` ${c.bold(name.padEnd(maxLen + 2))}${c.dim(desc)}`);
23853
+ }
23854
+ }
23855
+ return `
23856
+ ` + sections.join(`
23857
+ `) + `
23858
+ `;
23859
+ };
23860
+ }
23861
+
23542
23862
  // src/cli.ts
23543
23863
  import tabtab3 from "tabtab";
23544
23864
  var require3 = createRequire2(import.meta.url);
@@ -23593,6 +23913,7 @@ function resolveNoColorSetting(argv, env2) {
23593
23913
  return hasNoColorEnv;
23594
23914
  }
23595
23915
  var noColor = resolveNoColorSetting(process.argv, process.env);
23916
+ var buildHelpText = createHelpTextBuilder(noColor);
23596
23917
  var container = bootstrap({ noColor });
23597
23918
  function createContext(program2) {
23598
23919
  const opts = program2.opts();
@@ -23622,7 +23943,15 @@ function withGlobalOptions(options, context) {
23622
23943
  };
23623
23944
  }
23624
23945
  var cli = new Command;
23625
- cli.name("bb").description("A command-line interface for Bitbucket Cloud").version(pkg2.version).option("--json", "Output as JSON").option("--no-color", "Disable color output").option("-w, --workspace <workspace>", "Specify workspace").option("-r, --repo <repo>", "Specify repository").action(async () => {
23946
+ cli.name("bb").description("A command-line interface for Bitbucket Cloud").version(pkg2.version).option("--json", "Output as JSON").option("--no-color", "Disable color output").option("-w, --workspace <workspace>", "Specify workspace").option("-r, --repo <repo>", "Specify repository").addHelpText("after", buildHelpText({
23947
+ envVars: {
23948
+ BB_USERNAME: "Bitbucket username (fallback for auth login)",
23949
+ BB_API_TOKEN: "Bitbucket API token (fallback for auth login)",
23950
+ NO_COLOR: "Disable color output when set",
23951
+ FORCE_COLOR: "Force color output when set (and not '0')",
23952
+ DEBUG: "Enable HTTP debug logging when 'true'"
23953
+ }
23954
+ })).action(async () => {
23626
23955
  cli.outputHelp();
23627
23956
  const versionService = container.resolve(ServiceTokens.VersionService);
23628
23957
  const output = container.resolve(ServiceTokens.OutputService);
@@ -23639,116 +23968,255 @@ cli.name("bb").description("A command-line interface for Bitbucket Cloud").versi
23639
23968
  } catch {}
23640
23969
  });
23641
23970
  var authCmd = new Command("auth").description("Authenticate with Bitbucket");
23642
- authCmd.command("login").description("Authenticate with Bitbucket using an API token").option("-u, --username <username>", "Bitbucket username").option("-p, --password <password>", "Bitbucket API token").action(async (options) => {
23971
+ authCmd.command("login").description("Authenticate with Bitbucket using an API token").option("-u, --username <username>", "Bitbucket username").option("-p, --password <password>", "Bitbucket API token").addHelpText("after", buildHelpText({
23972
+ examples: [
23973
+ "bb auth login -u myuser -p mytoken",
23974
+ "BB_USERNAME=myuser BB_API_TOKEN=mytoken bb auth login"
23975
+ ],
23976
+ envVars: {
23977
+ BB_USERNAME: "Used when --username is not provided",
23978
+ BB_API_TOKEN: "Used when --password is not provided"
23979
+ }
23980
+ })).action(async (options) => {
23643
23981
  await runCommand(ServiceTokens.LoginCommand, options, cli);
23644
23982
  });
23645
- authCmd.command("logout").description("Log out of Bitbucket").action(async () => {
23983
+ authCmd.command("logout").description("Log out of Bitbucket").addHelpText("after", buildHelpText({ examples: ["bb auth logout"] })).action(async () => {
23646
23984
  await runCommand(ServiceTokens.LogoutCommand, undefined, cli);
23647
23985
  });
23648
- authCmd.command("status").description("Show authentication status").action(async () => {
23986
+ authCmd.command("status").description("Show authentication status").addHelpText("after", buildHelpText({
23987
+ examples: ["bb auth status", "bb auth status --json"]
23988
+ })).action(async () => {
23649
23989
  await runCommand(ServiceTokens.StatusCommand, undefined, cli);
23650
23990
  });
23651
- authCmd.command("token").description("Print the current access token").action(async () => {
23991
+ authCmd.command("token").description("Print the current access token").addHelpText("after", buildHelpText({
23992
+ examples: ["bb auth token", "bb auth token | pbcopy"]
23993
+ })).action(async () => {
23652
23994
  await runCommand(ServiceTokens.TokenCommand, undefined, cli);
23653
23995
  });
23654
23996
  cli.addCommand(authCmd);
23655
23997
  var repoCmd = new Command("repo").description("Manage repositories");
23656
- repoCmd.command("clone <repository>").description("Clone a Bitbucket repository").option("-d, --directory <dir>", "Directory to clone into").action(async (repository, options) => {
23998
+ repoCmd.command("clone <repository>").description("Clone a Bitbucket repository").option("-d, --directory <dir>", "Directory to clone into").addHelpText("after", buildHelpText({
23999
+ examples: [
24000
+ "bb repo clone workspace/repo-name",
24001
+ "bb repo clone workspace/repo-name -d my-directory"
24002
+ ]
24003
+ })).action(async (repository, options) => {
23657
24004
  await runCommand(ServiceTokens.CloneCommand, { repository, ...options }, cli);
23658
24005
  });
23659
- repoCmd.command("create <name>").description("Create a new repository").option("-d, --description <description>", "Repository description").option("--private", "Create a private repository (default)").option("--public", "Create a public repository").option("-p, --project <project>", "Project key").action(async (name, options) => {
24006
+ repoCmd.command("create <name>").description("Create a new repository").option("-d, --description <description>", "Repository description").option("--private", "Create a private repository (default)").option("--public", "Create a public repository").option("-p, --project <project>", "Project key").addHelpText("after", buildHelpText({
24007
+ examples: [
24008
+ "bb repo create my-repo",
24009
+ "bb repo create my-repo --public -p PROJ",
24010
+ 'bb repo create my-repo -d "My new repository"'
24011
+ ],
24012
+ defaults: { private: "true (visibility is private unless --public)" }
24013
+ })).action(async (name, options) => {
23660
24014
  const context = createContext(cli);
23661
24015
  await runCommand(ServiceTokens.CreateRepoCommand, withGlobalOptions({ name, ...options }, context), cli, context);
23662
24016
  });
23663
- repoCmd.command("list").description("List repositories").option("--limit <number>", "Maximum number of repositories to list", "25").action(async (options) => {
24017
+ repoCmd.command("list").description("List repositories").option("--limit <number>", "Maximum number of repositories to list", "25").addHelpText("after", buildHelpText({
24018
+ examples: [
24019
+ "bb repo list",
24020
+ "bb repo list --limit 50",
24021
+ "bb repo list --json"
24022
+ ],
24023
+ defaults: { limit: "25" }
24024
+ })).action(async (options) => {
23664
24025
  const context = createContext(cli);
23665
24026
  await runCommand(ServiceTokens.ListReposCommand, withGlobalOptions(options, context), cli, context);
23666
24027
  });
23667
- repoCmd.command("view [repository]").description("View repository details").action(async (repository, options) => {
24028
+ repoCmd.command("view [repository]").description("View repository details").addHelpText("after", buildHelpText({
24029
+ examples: [
24030
+ "bb repo view",
24031
+ "bb repo view workspace/repo-name",
24032
+ "bb repo view workspace/repo-name --json"
24033
+ ]
24034
+ })).action(async (repository, options) => {
23668
24035
  const context = createContext(cli);
23669
24036
  await runCommand(ServiceTokens.ViewRepoCommand, withGlobalOptions({ repository, ...options }, context), cli, context);
23670
24037
  });
23671
- repoCmd.command("delete <repository>").description("Delete a repository").option("-y, --yes", "Skip confirmation prompt").action(async (repository, options) => {
24038
+ repoCmd.command("delete <repository>").description("Delete a repository").option("-y, --yes", "Skip confirmation prompt").addHelpText("after", buildHelpText({
24039
+ examples: [
24040
+ "bb repo delete workspace/repo-name",
24041
+ "bb repo delete workspace/repo-name --yes"
24042
+ ]
24043
+ })).action(async (repository, options) => {
23672
24044
  const context = createContext(cli);
23673
24045
  await runCommand(ServiceTokens.DeleteRepoCommand, withGlobalOptions({ repository, ...options }, context), cli, context);
23674
24046
  });
23675
24047
  cli.addCommand(repoCmd);
23676
24048
  var prCmd = new Command("pr").description("Manage pull requests");
23677
- prCmd.command("create").description("Create a pull request").option("-t, --title <title>", "Pull request title").option("-b, --body <body>", "Pull request description").option("-s, --source <branch>", "Source branch (default: current branch)").option("-d, --destination <branch>", "Destination branch (default: main)").option("--close-source-branch", "Close source branch after merge").option("--draft", "Create the pull request as draft").action(async (options) => {
24049
+ prCmd.command("create").description("Create a pull request").option("-t, --title <title>", "Pull request title").option("-b, --body <body>", "Pull request description").option("-s, --source <branch>", "Source branch (default: current branch)").option("-d, --destination <branch>", "Destination branch (default: main)").option("--close-source-branch", "Close source branch after merge").option("--draft", "Create the pull request as draft").addHelpText("after", buildHelpText({
24050
+ examples: [
24051
+ 'bb pr create -t "My PR" -b "Description"',
24052
+ 'bb pr create -t "My PR" --draft',
24053
+ 'bb pr create -t "My PR" -s feature -d develop',
24054
+ 'bb pr create -t "My PR" --close-source-branch'
24055
+ ],
24056
+ defaults: {
24057
+ source: "current git branch",
24058
+ destination: "main"
24059
+ }
24060
+ })).action(async (options) => {
23678
24061
  const context = createContext(cli);
23679
24062
  await runCommand(ServiceTokens.CreatePRCommand, withGlobalOptions(options, context), cli, context);
23680
24063
  });
23681
- prCmd.command("list").description("List pull requests").option("-s, --state <state>", "Filter by state (OPEN, MERGED, DECLINED, SUPERSEDED)", "OPEN").option("--limit <number>", "Maximum number of PRs to list", "25").action(async (options) => {
24064
+ prCmd.command("list").description("List pull requests").option("-s, --state <state>", "Filter by state (OPEN, MERGED, DECLINED, SUPERSEDED)", "OPEN").option("--limit <number>", "Maximum number of PRs to list", "25").addHelpText("after", buildHelpText({
24065
+ examples: [
24066
+ "bb pr list",
24067
+ "bb pr list -s MERGED --limit 10",
24068
+ "bb pr list --json"
24069
+ ],
24070
+ validValues: {
24071
+ "Valid states": ["OPEN", "MERGED", "DECLINED", "SUPERSEDED"]
24072
+ },
24073
+ defaults: { state: "OPEN", limit: "25" }
24074
+ })).action(async (options) => {
23682
24075
  const context = createContext(cli);
23683
24076
  await runCommand(ServiceTokens.ListPRsCommand, withGlobalOptions(options, context), cli, context);
23684
24077
  });
23685
- prCmd.command("view <id>").description("View pull request details").action(async (id, options) => {
24078
+ prCmd.command("view <id>").description("View pull request details").addHelpText("after", buildHelpText({
24079
+ examples: ["bb pr view 42", "bb pr view 42 --json"]
24080
+ })).action(async (id, options) => {
23686
24081
  const context = createContext(cli);
23687
24082
  await runCommand(ServiceTokens.ViewPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23688
24083
  });
23689
- prCmd.command("activity <id>").description("Show pull request activity log").option("--limit <number>", "Maximum number of activity entries", "25").option("--type <types>", "Filter activity by type (comma-separated)").action(async (id, options) => {
24084
+ prCmd.command("activity <id>").description("Show pull request activity log").option("--limit <number>", "Maximum number of activity entries", "25").option("--type <types>", "Filter activity by type (comma-separated)").addHelpText("after", buildHelpText({
24085
+ examples: [
24086
+ "bb pr activity 42",
24087
+ "bb pr activity 42 --type comment,approval",
24088
+ "bb pr activity 42 --limit 10 --json"
24089
+ ],
24090
+ validValues: {
24091
+ "Valid activity types (comma-separated)": [
24092
+ "comment",
24093
+ "approval",
24094
+ "changes_requested",
24095
+ "merge",
24096
+ "decline",
24097
+ "commit",
24098
+ "update"
24099
+ ]
24100
+ },
24101
+ defaults: { limit: "25" }
24102
+ })).action(async (id, options) => {
23690
24103
  const context = createContext(cli);
23691
24104
  await runCommand(ServiceTokens.ActivityPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23692
24105
  });
23693
- prCmd.command("checks <id>").description("Show CI/CD checks and build status for a pull request").option("--json", "Output as JSON").action(async (id, options) => {
24106
+ prCmd.command("checks <id>").description("Show CI/CD checks and build status for a pull request").option("--json", "Output as JSON").addHelpText("after", buildHelpText({
24107
+ examples: ["bb pr checks 42", "bb pr checks 42 --json"]
24108
+ })).action(async (id, options) => {
23694
24109
  const context = createContext(cli);
23695
24110
  await runCommand(ServiceTokens.ChecksPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23696
24111
  });
23697
- prCmd.command("edit [id]").description("Edit a pull request").option("-t, --title <title>", "New pull request title").option("-b, --body <body>", "New pull request description").option("-F, --body-file <file>", "Read description from file").action(async (id, options) => {
24112
+ prCmd.command("edit [id]").description("Edit a pull request").option("-t, --title <title>", "New pull request title").option("-b, --body <body>", "New pull request description").option("-F, --body-file <file>", "Read description from file").addHelpText("after", buildHelpText({
24113
+ examples: [
24114
+ 'bb pr edit 42 -t "New title"',
24115
+ 'bb pr edit 42 -b "Updated description"',
24116
+ "bb pr edit 42 -F description.md",
24117
+ "bb pr edit"
24118
+ ]
24119
+ })).action(async (id, options) => {
23698
24120
  const context = createContext(cli);
23699
24121
  await runCommand(ServiceTokens.EditPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23700
24122
  });
23701
- prCmd.command("merge <id>").description("Merge a pull request").option("-m, --message <message>", "Merge commit message").option("--close-source-branch", "Delete the source branch after merging").option("--strategy <strategy>", "Merge strategy (merge_commit, squash, fast_forward)").action(async (id, options) => {
24123
+ prCmd.command("merge <id>").description("Merge a pull request").option("-m, --message <message>", "Merge commit message").option("--close-source-branch", "Delete the source branch after merging").option("--strategy <strategy>", "Merge strategy").addHelpText("after", buildHelpText({
24124
+ examples: [
24125
+ "bb pr merge 42",
24126
+ "bb pr merge 42 --strategy squash --close-source-branch",
24127
+ 'bb pr merge 42 -m "Merge feature X"'
24128
+ ],
24129
+ validValues: {
24130
+ "Valid merge strategies": [
24131
+ "merge_commit",
24132
+ "squash",
24133
+ "fast_forward",
24134
+ "squash_fast_forward",
24135
+ "rebase_fast_forward",
24136
+ "rebase_merge"
24137
+ ]
24138
+ }
24139
+ })).action(async (id, options) => {
23702
24140
  const context = createContext(cli);
23703
24141
  await runCommand(ServiceTokens.MergePRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23704
24142
  });
23705
- prCmd.command("approve <id>").description("Approve a pull request").action(async (id, options) => {
24143
+ prCmd.command("approve <id>").description("Approve a pull request").addHelpText("after", buildHelpText({ examples: ["bb pr approve 42"] })).action(async (id, options) => {
23706
24144
  const context = createContext(cli);
23707
24145
  await runCommand(ServiceTokens.ApprovePRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23708
24146
  });
23709
- prCmd.command("decline <id>").description("Decline a pull request").action(async (id, options) => {
24147
+ prCmd.command("decline <id>").description("Decline a pull request").addHelpText("after", buildHelpText({ examples: ["bb pr decline 42"] })).action(async (id, options) => {
23710
24148
  const context = createContext(cli);
23711
24149
  await runCommand(ServiceTokens.DeclinePRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23712
24150
  });
23713
- prCmd.command("ready <id>").description("Mark a draft pull request as ready for review").action(async (id, options) => {
24151
+ prCmd.command("ready <id>").description("Mark a draft pull request as ready for review").addHelpText("after", buildHelpText({ examples: ["bb pr ready 42"] })).action(async (id, options) => {
23714
24152
  const context = createContext(cli);
23715
24153
  await runCommand(ServiceTokens.ReadyPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23716
24154
  });
23717
- prCmd.command("checkout <id>").description("Checkout a pull request locally").action(async (id, options) => {
24155
+ prCmd.command("checkout <id>").description("Checkout a pull request locally").addHelpText("after", buildHelpText({ examples: ["bb pr checkout 42"] })).action(async (id, options) => {
23718
24156
  const context = createContext(cli);
23719
24157
  await runCommand(ServiceTokens.CheckoutPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23720
24158
  });
23721
- prCmd.command("diff [id]").description("View pull request diff").option("--color <when>", "Colorize output (auto, always, never)", "auto").option("--name-only", "Show only names of changed files").option("--stat", "Show diffstat").option("--web", "Open diff in web browser").action(async (id, options) => {
24159
+ prCmd.command("diff [id]").description("View pull request diff").option("--color <when>", "Colorize output", "auto").option("--name-only", "Show only names of changed files").option("--stat", "Show diffstat").option("--web", "Open diff in web browser").addHelpText("after", buildHelpText({
24160
+ examples: [
24161
+ "bb pr diff 42",
24162
+ "bb pr diff 42 --stat",
24163
+ "bb pr diff 42 --name-only",
24164
+ "bb pr diff --web",
24165
+ "bb pr diff 42 --color always"
24166
+ ],
24167
+ validValues: {
24168
+ "Valid --color values": ["auto", "always", "never"]
24169
+ },
24170
+ defaults: { color: "auto" }
24171
+ })).action(async (id, options) => {
23722
24172
  const context = createContext(cli);
23723
24173
  await runCommand(ServiceTokens.DiffPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23724
24174
  });
23725
24175
  var prCommentsCmd = new Command("comments").description("Manage pull request comments");
23726
- prCommentsCmd.command("list <id>").description("List comments on a pull request").option("--limit <number>", "Maximum number of comments (default: 25)").option("--no-truncate", "Show full comment content without truncation").action(async (id, options) => {
24176
+ prCommentsCmd.command("list <id>").description("List comments on a pull request").option("--limit <number>", "Maximum number of comments (default: 25)").option("--no-truncate", "Show full comment content without truncation").addHelpText("after", buildHelpText({
24177
+ examples: [
24178
+ "bb pr comments list 42",
24179
+ "bb pr comments list 42 --no-truncate",
24180
+ "bb pr comments list 42 --limit 50 --json"
24181
+ ],
24182
+ defaults: { limit: "25" }
24183
+ })).action(async (id, options) => {
23727
24184
  const context = createContext(cli);
23728
24185
  await runCommand(ServiceTokens.ListCommentsPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23729
24186
  });
23730
- prCommentsCmd.command("add <id> <message>").description("Add a comment to a pull request").option("--file <path>", "File path in the diff for inline comment").option("--line-to <number>", "Line number in the new file version").option("--line-from <number>", "Line number in the old file version").action(async (id, message, options) => {
24187
+ prCommentsCmd.command("add <id> <message>").description("Add a comment to a pull request").option("--file <path>", "File path in the diff for inline comment").option("--line-to <number>", "Line number in the new file version").option("--line-from <number>", "Line number in the old file version").addHelpText("after", buildHelpText({
24188
+ examples: [
24189
+ 'bb pr comments add 42 "LGTM"',
24190
+ 'bb pr comments add 42 "Fix this" --file src/main.ts --line-to 10'
24191
+ ]
24192
+ })).action(async (id, message, options) => {
23731
24193
  const context = createContext(cli);
23732
24194
  await runCommand(ServiceTokens.CommentPRCommand, withGlobalOptions({ id, message, ...options }, context), cli, context);
23733
24195
  });
23734
- prCommentsCmd.command("edit <pr-id> <comment-id> <message>").description("Edit a comment on a pull request").action(async (prId, commentId, message, options) => {
24196
+ prCommentsCmd.command("edit <pr-id> <comment-id> <message>").description("Edit a comment on a pull request").addHelpText("after", buildHelpText({
24197
+ examples: ['bb pr comments edit 42 12345 "Updated comment"']
24198
+ })).action(async (prId, commentId, message, options) => {
23735
24199
  const context = createContext(cli);
23736
24200
  await runCommand(ServiceTokens.EditCommentPRCommand, withGlobalOptions({ prId, commentId, message }, context), cli, context);
23737
24201
  });
23738
- prCommentsCmd.command("delete <pr-id> <comment-id>").description("Delete a comment on a pull request").action(async (prId, commentId, options) => {
24202
+ prCommentsCmd.command("delete <pr-id> <comment-id>").description("Delete a comment on a pull request").addHelpText("after", buildHelpText({
24203
+ examples: ["bb pr comments delete 42 12345"]
24204
+ })).action(async (prId, commentId, options) => {
23739
24205
  const context = createContext(cli);
23740
24206
  await runCommand(ServiceTokens.DeleteCommentPRCommand, withGlobalOptions({ prId, commentId }, context), cli, context);
23741
24207
  });
23742
24208
  var prReviewersCmd = new Command("reviewers").description("Manage pull request reviewers");
23743
- prReviewersCmd.command("list <id>").description("List reviewers on a pull request").action(async (id, options) => {
24209
+ prReviewersCmd.command("list <id>").description("List reviewers on a pull request").addHelpText("after", buildHelpText({
24210
+ examples: ["bb pr reviewers list 42", "bb pr reviewers list 42 --json"]
24211
+ })).action(async (id, options) => {
23744
24212
  const context = createContext(cli);
23745
24213
  await runCommand(ServiceTokens.ListReviewersPRCommand, withGlobalOptions({ id, ...options }, context), cli, context);
23746
24214
  });
23747
- prReviewersCmd.command("add <id> <username>").description("Add a reviewer to a pull request").action(async (id, username, options) => {
24215
+ prReviewersCmd.command("add <id> <username>").description("Add a reviewer to a pull request").addHelpText("after", buildHelpText({ examples: ["bb pr reviewers add 42 jdoe"] })).action(async (id, username, options) => {
23748
24216
  const context = createContext(cli);
23749
24217
  await runCommand(ServiceTokens.AddReviewerPRCommand, withGlobalOptions({ id, username, ...options }, context), cli, context);
23750
24218
  });
23751
- prReviewersCmd.command("remove <id> <username>").description("Remove a reviewer from a pull request").action(async (id, username, options) => {
24219
+ prReviewersCmd.command("remove <id> <username>").description("Remove a reviewer from a pull request").addHelpText("after", buildHelpText({ examples: ["bb pr reviewers remove 42 jdoe"] })).action(async (id, username, options) => {
23752
24220
  const context = createContext(cli);
23753
24221
  await runCommand(ServiceTokens.RemoveReviewerPRCommand, withGlobalOptions({ id, username, ...options }, context), cli, context);
23754
24222
  });
@@ -23756,21 +24224,46 @@ cli.addCommand(prCmd);
23756
24224
  prCmd.addCommand(prCommentsCmd);
23757
24225
  prCmd.addCommand(prReviewersCmd);
23758
24226
  var configCmd = new Command("config").description("Manage configuration");
23759
- configCmd.command("get <key>").description("Get a configuration value").action(async (key) => {
24227
+ configCmd.command("get <key>").description("Get a configuration value").addHelpText("after", buildHelpText({
24228
+ examples: ["bb config get defaultWorkspace"],
24229
+ validValues: {
24230
+ "Readable config keys": [
24231
+ "username",
24232
+ "defaultWorkspace",
24233
+ "skipVersionCheck",
24234
+ "versionCheckInterval"
24235
+ ]
24236
+ }
24237
+ })).action(async (key) => {
23760
24238
  await runCommand(ServiceTokens.GetConfigCommand, { key }, cli);
23761
24239
  });
23762
- configCmd.command("set <key> <value>").description("Set a configuration value").action(async (key, value) => {
24240
+ configCmd.command("set <key> <value>").description("Set a configuration value").addHelpText("after", buildHelpText({
24241
+ examples: [
24242
+ "bb config set defaultWorkspace my-workspace",
24243
+ "bb config set skipVersionCheck true",
24244
+ "bb config set versionCheckInterval 86400"
24245
+ ],
24246
+ validValues: {
24247
+ "Settable config keys": [
24248
+ "defaultWorkspace (string)",
24249
+ "skipVersionCheck (true/false)",
24250
+ "versionCheckInterval (positive integer, seconds)"
24251
+ ]
24252
+ }
24253
+ })).action(async (key, value) => {
23763
24254
  await runCommand(ServiceTokens.SetConfigCommand, { key, value }, cli);
23764
24255
  });
23765
- configCmd.command("list").description("List all configuration values").action(async () => {
24256
+ configCmd.command("list").description("List all configuration values").addHelpText("after", buildHelpText({
24257
+ examples: ["bb config list", "bb config list --json"]
24258
+ })).action(async () => {
23766
24259
  await runCommand(ServiceTokens.ListConfigCommand, undefined, cli);
23767
24260
  });
23768
24261
  cli.addCommand(configCmd);
23769
24262
  var completionCmd = new Command("completion").description("Shell completion utilities");
23770
- completionCmd.command("install").description("Install shell completions for bash, zsh, or fish").action(async () => {
24263
+ completionCmd.command("install").description("Install shell completions for bash, zsh, or fish").addHelpText("after", buildHelpText({ examples: ["bb completion install"] })).action(async () => {
23771
24264
  await runCommand(ServiceTokens.InstallCompletionCommand, undefined, cli);
23772
24265
  });
23773
- completionCmd.command("uninstall").description("Uninstall shell completions").action(async () => {
24266
+ completionCmd.command("uninstall").description("Uninstall shell completions").addHelpText("after", buildHelpText({ examples: ["bb completion uninstall"] })).action(async () => {
23774
24267
  await runCommand(ServiceTokens.UninstallCompletionCommand, undefined, cli);
23775
24268
  });
23776
24269
  cli.addCommand(completionCmd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pilatos/bitbucket-cli",
3
- "version": "1.8.2",
3
+ "version": "1.8.4",
4
4
  "description": "A command-line interface for Bitbucket Cloud",
5
5
  "author": "",
6
6
  "license": "MIT",