Add 'last' subcommand to resume most recent session - #117
Conversation
f73c7ab to
fce9f9d
Compare
sorafujitani
left a comment
There was a problem hiding this comment.
実動作で再現する問題があるため、修正をお願いします。
| return "", fmt.Errorf("no sessions found") | ||
| } | ||
| latest := sessions[0] | ||
| return latest.ID, nil |
There was a problem hiding this comment.
IDだけを返すと、同じIDのJSONLが複数ある場合に resume.Run が別のセッションを再検索してしまいます。source.LocatorFor(latest) も返し、resumeへ渡してください。
There was a problem hiding this comment.
分かりました!
こちら修正しました。
| if len(sessions) == 0 { | ||
| return "", fmt.Errorf("no sessions found") | ||
| } | ||
| latest := sessions[0] |
There was a problem hiding this comment.
Issue #41 の仕様どおり、cwdが消滅・不明なセッションはスキップして、次の再開可能なセッションを選んでください。現在は後段でエラーになります。
There was a problem hiding this comment.
読み飛ばし失礼しました。
こちら対応しました!
| excludeDirFlag := fs.String("exclude-dir", os.Getenv(excludeDirEnv), "hide sessions whose cwd contains <s> (case-insensitive)") | ||
| nFlag := fs.Bool("n", false, "dry-run: print what would be resumed") | ||
|
|
||
| if err := fs.Parse(args); err != nil { |
There was a problem hiding this comment.
fs.NArg() == 0 を検証してください。ccsession last typo -n では -n が無視され、意図せずresumeが実行されます。
There was a problem hiding this comment.
こちら対応しました!
テストケースも追加しています。
| return "", err | ||
| } | ||
| for i := len(sessions) - 1; i >= 0; i-- { | ||
| if sessions[i].CWD != currentDir && !strings.HasPrefix(sessions[i].CWD, currentDir+"/") { |
There was a problem hiding this comment.
現在地が / だとprefixが // になり、--here が全件除外します。filepath.Rel などで配下判定してください。
There was a problem hiding this comment.
func isUnderOrEqual(base, target string) bool {
rel, err := filepath.Rel(base, target)
if err != nil {
return false
}
if rel == "." {
return true
}
prefix := ".." + string(os.PathSeparator)
return rel != ".." && !strings.HasPrefix(rel, prefix)
}
こんな関数を作ってみました!
指摘のところで呼び出してチェックするように変えました。
また、テストでもこの関数の単体テストを追加しました。
fce9f9d to
1cc99aa
Compare
Implements `ccsession last` to resume the most recent session without launching the picker. - Support --here, --exclude-dir, and -n flags - Add internal/last package with Run() and tests Closes #41
ac4d1a5 to
3b4e2fc
Compare
|
レビューありがとうございます! CI落ちているのですが、今回のスコープ外と判断しております。 -- やったこと
|
Summary
Implements
ccsession lastsubcommand to resume the most recent session without launching the picker.Related issue
#41
Type of change
How was this tested?
Automated tests
TestRun_Basic: verifies the most recent session ID is returnedTestFilterOutByDir: verifies directory filtering behaviorManual testing
Checklist
gofmt -l .reports nothinggo vet ./...passesgo test ./...passesREADME.mdetc.) updated for any user-facing change