Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ go.work.sum
# env file
.env

# Editor/IDE
# .idea/
# .vscode/

# Editor/IDE
.claude/

test/
.DS_Store
2 changes: 1 addition & 1 deletion .issues/.counter
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21
22
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
id: "021"
assignee: ""
labels:
- feature
created: 2026-02-06T14:27:24.912527+09:00
updated: 2026-02-06T14:40:03.891202+09:00
---

# Add view command to open issue markdown in default program

## Description

Add a new `gi view` command that opens an issue's markdown file using the system's default program associated with the `.md` extension. This allows users to quickly view or edit issues in their preferred markdown editor or viewer (e.g., Typora, VS Code, Obsidian).

Usage: `gi view 001`

## Requirements

- Accept an issue ID as argument (e.g., `gi view 001`)
- Look up the issue file in `.issues/open/` and `.issues/closed/`
- Open the file using the OS default program for `.md` files:
- macOS: use `open` command
- Linux: use `xdg-open` command
- Show an error if the issue ID is not found

## Success Criteria

- [ ] `gi view <id>` opens the issue markdown in the default associated program
- [ ] Works on macOS (`open`) and Linux (`xdg-open`)
- [ ] Displays clear error when issue ID does not exist
- [ ] Unit tests for file lookup logic
- [ ] Update README file
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ gi edit 001
# Opens the issue file in $EDITOR (defaults to vim)
```

### View an issue in default program

```bash
gi view 001
# Opens the issue markdown file in the system's default program
```

### Search issues

```bash
Expand Down
52 changes: 52 additions & 0 deletions cmd/view.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package cmd

import (
"fmt"
"os/exec"
"runtime"

"github.com/Allra-Fintech/git-issue/pkg"
"github.com/fatih/color"
"github.com/spf13/cobra"
)

var viewCmd = &cobra.Command{
Use: "view <issue-id>",
Short: "Open an issue in the default program",
Long: `Open an issue's markdown file in the system's default program (e.g., Typora, VS Code, Obsidian).`,
Args: cobra.ExactArgs(1),
RunE: runView,
}

func init() {
rootCmd.AddCommand(viewCmd)
}

func runView(cmd *cobra.Command, args []string) error {
issueID := args[0]

// Find the issue file
path, _, err := pkg.FindIssueFile(issueID)
if err != nil {
return fmt.Errorf("failed to find issue: %w", err)
}

// Determine the OS-appropriate open command
var opener string
switch runtime.GOOS {
case "darwin":
opener = "open"
case "linux":
opener = "xdg-open"
default:
return fmt.Errorf("unsupported platform: %s", runtime.GOOS)
}

// Open the file in the default program (non-blocking)
if err := exec.Command(opener, path).Start(); err != nil {
return fmt.Errorf("failed to open file: %w", err)
}

color.New(color.FgGreen).Printf("✓ Opened issue #%s in default program\n", issueID)
return nil
}
21 changes: 21 additions & 0 deletions cmd/view_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"testing"
)

func TestViewMissingArgs(t *testing.T) {
cmd := viewCmd
err := cmd.Args(cmd, []string{})
if err == nil {
t.Error("expected error for missing arguments")
}
}

func TestViewNonExistentIssue(t *testing.T) {
// runView should fail when the issue doesn't exist
err := runView(viewCmd, []string{"999"})
if err == nil {
t.Error("expected error for non-existent issue")
}
}