Skip to content

Commit

Permalink
Merge pull request #6 from daido1976/show-name-option
Browse files Browse the repository at this point in the history
Add `--name-only` option to show subcommand
  • Loading branch information
daido1976 authored May 15, 2022
2 parents f49d94f + 3dffd9c commit 8feef24
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 46 deletions.
21 changes: 8 additions & 13 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
name: Check

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
on: push

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Check
run: cargo check --verbose
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Check
run: cargo check --verbose
233 changes: 232 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[package]
description = "GitHub CLI extension to show & rename the default branch"
edition = "2021"
name = "gh-default-branch"
version = "0.1.0"
version = "0.6.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = {version = "3.1.18", features = ["derive"]}
52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,60 @@ $ gh extension install daido1976/gh-default-branch

```sh
$ gh default-branch -h
# Usage: gh default-branch
# gh default-branch 0.6.0
# GitHub CLI extension to show & rename the default branch
#
# USAGE:
# gh-default-branch <SUBCOMMAND>
#
# OPTIONS:
# -h, --help Print help information
# -V, --version Print version information
#
# SUBCOMMANDS:
# help Print this message or the help of the given subcommand(s)
# rename Rename default branch
# show Show default branch

$ gh default-branch show -h
# gh-default-branch-show
# Show default branch
# $ gh default-branch show
#
# USAGE:
# gh-default-branch show [OPTIONS]
#
# OPTIONS:
# -h, --help Print help information
# -n, --name-only Show only the branch name (e.g. main)

$ gh default-branch rename -h
# gh-default-branch-rename
# Rename default branch
# $ gh default-branch rename <name>
#
# USAGE:
# gh-default-branch rename <NAME>
#
# ARGS:
# <NAME>
#
# OPTIONS:
# -h, --help Print help information
```

## Release
## Development

### Debug

```sh
$ gh extension install .
$ gh default-branch <SUBCOMMAND>
```

### Release

This extension is released as a precompiled extension.

See. https://docs.github.com/en/github-cli/github-cli/creating-github-cli-extensions#creating-a-precompiled-extension-manually

```sh
$ git tag <version(e.g.`v0.1`)>
Expand Down
6 changes: 6 additions & 0 deletions gh-default-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

# for debug
cargo build --release
target/release/gh-default-branch "$@"
18 changes: 6 additions & 12 deletions src/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::process::{Command, Output};

pub fn show() {
pub fn show(name_only: bool) {
let repo_name_with_owner = get_repo_name_with_owner();
let default_branch = get_default_branch(&repo_name_with_owner);
println!("Current default branch is \"{}\"", default_branch,);
if name_only {
println!("{}", default_branch)
} else {
println!("Current default branch is \"{}\"", default_branch);
}
}

// TODO: Make it interactive because this is a command with a lot of side effects.
Expand All @@ -26,16 +30,6 @@ pub fn rename(to_branch: &str) {
);
}

pub fn help() {
println!(
"Usage: gh default-branch\n\n\
Show default branch\n\
$ gh default-branch show\n\n\
Rename default branch\n\
$ gh default-branch rename <name>"
);
}

/// e.g. daido1976/gh-default-branch
fn get_repo_name_with_owner() -> String {
// gh repo view --json nameWithOwner --jq .nameWithOwner
Expand Down
Loading

0 comments on commit 8feef24

Please sign in to comment.