Skip to content

Commit 1547bd8

Browse files
buty4649claude
andcommitted
document: --me の domain_code を保存済みOAuthトークンからも解決
--xpoint-domain-code / XPOINT_DOMAIN_CODE が未設定でも `xp auth login` で キーリングに保存された domain_code をフォールバックとして使うように resolveDomainCode を追加。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 90d11bf commit 1547bd8

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ xp document search --title 経費 # 件名部分一致
104104
xp document search --form-name 稟議 --form-group-id 3 # フォーム名 + フォームグループID
105105
xp document search --writer alice --writer bob # 申請者指定(複数可)
106106
xp document search --writer-group grp1 # 申請者グループ指定
107-
xp document search --me # 自分が申請者の書類(XPOINT_USER、未設定なら /scim/v2/{domain_code}/Me から取得)
107+
xp document search --me # 自分が申請者の書類(XPOINT_USER、未設定なら /scim/v2/{domain_code}/Me から取得。domain_code は保存済み OAuth トークンの値も利用
108108
xp document search --since 2024-01-01 --until 2024-12-31
109109
```
110110

cmd/document.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,9 @@ func resolveCurrentUserCode(ctx context.Context, client *xpoint.Client) (string,
476476
if u := pick(flagUser, "XPOINT_USER"); u != "" {
477477
return u, nil
478478
}
479-
domain := pick(flagDomainCode, "XPOINT_DOMAIN_CODE")
479+
domain := resolveDomainCode()
480480
if domain == "" {
481-
return "", fmt.Errorf("--me requires the current user code: set --xpoint-user / XPOINT_USER, or --xpoint-domain-code / XPOINT_DOMAIN_CODE to look it up via /scim/v2/{domain_code}/Me")
481+
return "", fmt.Errorf("--me requires the current user code: set --xpoint-user / XPOINT_USER, or provide a domain code (--xpoint-domain-code / XPOINT_DOMAIN_CODE / stored OAuth login) to look it up via /scim/v2/{domain_code}/Me")
482482
}
483483
info, err := client.GetSelfInfo(ctx, domain)
484484
if err != nil {

cmd/document_test.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,6 @@ func TestResolveCurrentUserCode_UsesEnvUser(t *testing.T) {
168168
}
169169
}
170170

171-
func TestResolveCurrentUserCode_ErrorsWithoutUserOrDomain(t *testing.T) {
172-
resetSearchFlags(t)
173-
t.Setenv("XPOINT_USER", "")
174-
t.Setenv("XPOINT_DOMAIN_CODE", "")
175-
176-
_, err := resolveCurrentUserCode(context.Background(), nil)
177-
if err == nil || !strings.Contains(err.Error(), "--xpoint-user") {
178-
t.Errorf("err = %v", err)
179-
}
180-
}
181171

182172
func TestRunDocumentSearch_BodyAndFilterConflict(t *testing.T) {
183173
resetSearchFlags(t)

cmd/root.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ func resolveSubdomain() (string, error) {
5959
return "", errors.New("subdomain is required: set --xpoint-subdomain or XPOINT_SUBDOMAIN, or run 'xp auth login' first")
6060
}
6161

62+
// resolveDomainCode returns the X-point domain code in priority order:
63+
// --xpoint-domain-code flag, XPOINT_DOMAIN_CODE env, then the domain code
64+
// saved alongside the OAuth token by `xp auth login`. Returns an empty
65+
// string if none is available.
66+
func resolveDomainCode() string {
67+
if d := pick(flagDomainCode, "XPOINT_DOMAIN_CODE"); d != "" {
68+
return d
69+
}
70+
if t, err := xpoint.LoadToken(); err == nil && t.DomainCode != "" {
71+
return t.DomainCode
72+
}
73+
return ""
74+
}
75+
6276
// authFromFlags returns the credential supplied via --xpoint-* command-line
6377
// flags. The bool is true only when the user explicitly passed flags. This is
6478
// the highest-priority auth source: a one-shot flag should always win.

0 commit comments

Comments
 (0)