Skip to content

Commit 97dd215

Browse files
authored
migrate Configuration usage to Settings (#211)
1 parent 23aa038 commit 97dd215

File tree

4 files changed

+83
-97
lines changed

4 files changed

+83
-97
lines changed

cmd/src/config.go

Lines changed: 41 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var configCommands commander
1111
func init() {
1212
usage := `'src config' is a tool that manages global, organization, and user settings on a Sourcegraph instance.
1313
14-
The effective configuration is computed by shallow-merging the following settings, in order from lowest to highest precedence:
14+
The effective setting is computed by shallow-merging the following settings, in order from lowest to highest precedence:
1515
1616
- Global settings (site-wide)
1717
- Organization settings for the user's organizations (if any)
@@ -26,9 +26,9 @@ Usage:
2626
2727
The commands are:
2828
29-
get gets the effective (merged) configuration
30-
edit updates configuration settings
31-
list lists the partial settings (that, when merged, yield the effective configuration)
29+
get gets the effective (merged) settings
30+
edit updates settings
31+
list lists the partial settings (that, when merged, yield the effective settings)
3232
3333
Use "src config [command] -h" for more information about a command.
3434
`
@@ -49,14 +49,12 @@ Use "src config [command] -h" for more information about a command.
4949
})
5050
}
5151

52-
const configurationSubjectFragment = `
53-
fragment ConfigurationSubjectFields on ConfigurationSubject {
52+
const settingsSubjectFragment = `
53+
fragment SettingsSubjectFields on SettingsSubject {
5454
id
5555
latestSettings {
5656
id
57-
configuration {
58-
...ConfigurationFields
59-
}
57+
contents
6058
author {
6159
...UserFields
6260
}
@@ -67,60 +65,48 @@ fragment ConfigurationSubjectFields on ConfigurationSubject {
6765
}
6866
`
6967

70-
type ConfigurationSubject struct {
71-
ID string
72-
LatestSettings *Settings
73-
SettingsURL string
74-
ViewerCanAdminister bool
75-
ConfigurationCascade ConfigurationCascade
68+
type SettingsSubject struct {
69+
ID string
70+
LatestSettings *Settings
71+
SettingsURL string
72+
ViewerCanAdminister bool
73+
SettingsCascade SettingsCascade
7674
}
7775

7876
type Settings struct {
79-
ID int32
80-
Configuration Configuration
81-
Author *User
82-
CreatedAt string
77+
ID int32
78+
Contents string
79+
Author *User
80+
CreatedAt string
8381
}
8482

85-
const configurationCascadeFragment = `
86-
fragment ConfigurationCascadeFields on ConfigurationCascade {
83+
const settingsCascadeFragment = `
84+
fragment SettingsCascadeFields on SettingsCascade {
8785
subjects {
88-
...ConfigurationSubjectFields
89-
}
90-
merged {
91-
...ConfigurationFields
86+
...SettingsSubjectFields
9287
}
88+
final
9389
}
9490
`
9591

96-
type ConfigurationCascade struct {
97-
Subjects []ConfigurationSubject
98-
Merged Configuration
99-
}
100-
101-
const configurationFragment = `
102-
fragment ConfigurationFields on Configuration {
103-
contents
104-
}
105-
`
106-
107-
type Configuration struct {
108-
Contents string
92+
type SettingsCascade struct {
93+
Subjects []SettingsSubject
94+
Final string
10995
}
11096

111-
const viewerConfigurationQuery = `query ViewerConfiguration {
112-
viewerConfiguration {
113-
...ConfigurationCascadeFields
97+
const viewerSettingsQuery = `query ViewerSettings {
98+
viewerSettings {
99+
...SettingsCascadeFields
114100
}
115-
}` + configurationCascadeFragment + configurationSubjectFragment + configurationFragment + userFragment
101+
}` + settingsCascadeFragment + settingsSubjectFragment + userFragment
116102

117-
const configurationSubjectCascadeQuery = `query ConfigurationSubjectCascade($subject: ID!) {
118-
configurationSubject(id: $subject) {
119-
configurationCascade {
120-
...ConfigurationCascadeFields
103+
const settingsSubjectCascadeQuery = `query SettingsSubjectCascade($subject: ID!) {
104+
settingsSubject(id: $subject) {
105+
settingsCascade {
106+
...SettingsCascadeFields
121107
}
122108
}
123-
}` + configurationCascadeFragment + configurationSubjectFragment + configurationFragment + userFragment
109+
}` + settingsCascadeFragment + settingsSubjectFragment + userFragment
124110

125111
type KeyPath struct {
126112
Property string `json:"property,omitempty"`
@@ -150,18 +136,18 @@ query ViewerUserID {
150136
return result.CurrentUser.ID, nil
151137
}
152138

153-
func getConfigurationSubjectLatestSettingsID(subjectID string) (*int, error) {
139+
func getSettingsSubjectLatestSettingsID(subjectID string) (*int, error) {
154140
var result struct {
155-
ConfigurationSubject *struct {
141+
SettingsSubject *struct {
156142
LatestSettings *struct {
157143
ID int
158144
}
159145
}
160146
}
161147
req := &apiRequest{
162148
query: `
163-
query ConfigurationSubjectLatestSettingsID($subject: ID!) {
164-
configurationSubject(id: $subject) {
149+
query SettingsSubjectLatestSettingsID($subject: ID!) {
150+
settingsSubject(id: $subject) {
165151
latestSettings {
166152
id
167153
}
@@ -174,11 +160,11 @@ query ConfigurationSubjectLatestSettingsID($subject: ID!) {
174160
if err := req.do(); err != nil {
175161
return nil, err
176162
}
177-
if result.ConfigurationSubject == nil {
178-
return nil, fmt.Errorf("unable to find configuration subject with ID %s", subjectID)
163+
if result.SettingsSubject == nil {
164+
return nil, fmt.Errorf("unable to find settings subject with ID %s", subjectID)
179165
}
180-
if result.ConfigurationSubject.LatestSettings == nil {
166+
if result.SettingsSubject.LatestSettings == nil {
181167
return nil, nil
182168
}
183-
return &result.ConfigurationSubject.LatestSettings.ID, nil
169+
return &result.SettingsSubject.LatestSettings.ID, nil
184170
}

cmd/src/config_edit.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ func init() {
1111
usage := `
1212
Examples:
1313
14-
Edit configuration property for the current user (authenticated by the src CLI's access token, if any):
14+
Edit settings property for the current user (authenticated by the src CLI's access token, if any):
1515
1616
$ src config edit -property motd -value '["Hello!"]'
1717
18-
Overwrite all configuration settings for the current user:
18+
Overwrite all settings settings for the current user:
1919
2020
$ src config edit -overwrite -value '{"motd":["Hello!"]}'
2121
22-
Overwrite all configuration settings for the current user with the file contents:
22+
Overwrite all settings settings for the current user with the file contents:
2323
2424
$ src config edit -overwrite -value-file myconfig.json
2525
26-
Edit a configuration property for the user with username alice:
26+
Edit a settings property for the user with username alice:
2727
2828
$ src config edit -subject=$(src users get -f '{{.ID}}' -username=alice) -property motd -value '["Hello!"]'
2929
30-
Overwrite all configuration settings for the organization named abc-org:
30+
Overwrite all settings settings for the organization named abc-org:
3131
3232
$ src config edit -subject=$(src orgs get -f '{{.ID}}' -name=abc-org) -overwrite -value '{"motd":["Hello!"]}'
3333
@@ -40,9 +40,9 @@ Examples:
4040
fmt.Println(usage)
4141
}
4242
var (
43-
subjectFlag = flagSet.String("subject", "", "The ID of the configuration subject whose configuration to edit. (default: authenticated user)")
44-
propertyFlag = flagSet.String("property", "", "The name of the configuration property to set.")
45-
valueFlag = flagSet.String("value", "", "The value for the configuration property (when used with -property).")
43+
subjectFlag = flagSet.String("subject", "", "The ID of the settings subject whose settings to edit. (default: authenticated user)")
44+
propertyFlag = flagSet.String("property", "", "The name of the settings property to set.")
45+
valueFlag = flagSet.String("value", "", "The value for the settings property (when used with -property).")
4646
valueFileFlag = flagSet.String("value-file", "", "Read the value from this file instead of from the -value command-line option.")
4747
overwriteFlag = flagSet.Bool("overwrite", false, "Overwrite the entire settings with the value given in -value (not just a single property).")
4848
apiFlags = newAPIFlags(flagSet)
@@ -85,15 +85,15 @@ Examples:
8585
subjectID = *subjectFlag
8686
}
8787

88-
lastID, err := getConfigurationSubjectLatestSettingsID(subjectID)
88+
lastID, err := getSettingsSubjectLatestSettingsID(subjectID)
8989
if err != nil {
9090
return err
9191
}
9292

9393
query := `
94-
mutation EditConfiguration($input: ConfigurationMutationGroupInput!, $edit: ConfigurationEdit!) {
95-
configurationMutation(input: $input) {
96-
editConfiguration(edit: $edit) {
94+
mutation EditSettings($input: SettingsMutationGroupInput!, $edit: SettingsEdit!) {
95+
settingsMutation(input: $input) {
96+
editSettings(edit: $edit) {
9797
empty {
9898
alwaysNil
9999
}
@@ -113,8 +113,8 @@ mutation EditConfiguration($input: ConfigurationMutationGroupInput!, $edit: Conf
113113
}
114114

115115
var result struct {
116-
ViewerConfiguration *ConfigurationCascade
117-
ConfigurationSubject *ConfigurationSubject
116+
ViewerSettings *SettingsCascade
117+
SettingsSubject *SettingsSubject
118118
}
119119
return (&apiRequest{
120120
query: query,

cmd/src/config_get.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ func init() {
99
usage := `
1010
Examples:
1111
12-
Get configuration for the current user (authenticated by the src CLI's access token, if any):
12+
Get settings for the current user (authenticated by the src CLI's access token, if any):
1313
1414
$ src config get
1515
16-
Get configuration for the user with username alice:
16+
Get settings for the user with username alice:
1717
1818
$ src config get -subject=$(src users get -f '{{.ID}}' -username=alice)
1919
20-
Get configuration for the organization named abc-org:
20+
Get settings for the organization named abc-org:
2121
2222
$ src config get -subject=$(src orgs get -f '{{.ID}}' -name=abc-org)
2323
@@ -30,8 +30,8 @@ Examples:
3030
fmt.Println(usage)
3131
}
3232
var (
33-
subjectFlag = flagSet.String("subject", "", "The ID of the configuration subject whose configuration to get. (default: authenticated user)")
34-
formatFlag = flagSet.String("f", "{{.Contents|jsonIndent}}", `Format for the output, using the syntax of Go package text/template. (e.g. "{{.|json}}")`)
33+
subjectFlag = flagSet.String("subject", "", "The ID of the settings subject whose settings to get. (default: authenticated user)")
34+
formatFlag = flagSet.String("f", "{{.|jsonIndent}}", `Format for the output, using the syntax of Go package text/template. (e.g. "{{.|json}}")`)
3535
apiFlags = newAPIFlags(flagSet)
3636
)
3737

@@ -49,30 +49,30 @@ Examples:
4949
var query string
5050
var queryVars map[string]interface{}
5151
if *subjectFlag == "" {
52-
query = viewerConfigurationQuery
52+
query = viewerSettingsQuery
5353
} else {
54-
query = configurationSubjectCascadeQuery
54+
query = settingsSubjectCascadeQuery
5555
queryVars = map[string]interface{}{
5656
"subject": nullString(*subjectFlag),
5757
}
5858
}
5959

6060
var result struct {
61-
ViewerConfiguration *ConfigurationCascade
62-
ConfigurationSubject *ConfigurationSubject
61+
ViewerSettings *SettingsCascade
62+
SettingsSubject *SettingsSubject
6363
}
6464
return (&apiRequest{
6565
query: query,
6666
vars: queryVars,
6767
result: &result,
6868
done: func() error {
69-
var merged Configuration
70-
if result.ViewerConfiguration != nil {
71-
merged = result.ViewerConfiguration.Merged
72-
} else if result.ConfigurationSubject != nil {
73-
merged = result.ConfigurationSubject.ConfigurationCascade.Merged
69+
var final string
70+
if result.ViewerSettings != nil {
71+
final = result.ViewerSettings.Final
72+
} else if result.SettingsSubject != nil {
73+
final = result.SettingsSubject.SettingsCascade.Final
7474
}
75-
return execTemplate(tmpl, merged)
75+
return execTemplate(tmpl, final)
7676
},
7777
flags: apiFlags,
7878
}).do()

cmd/src/config_list.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ func init() {
99
usage := `
1010
Examples:
1111
12-
List configuration settings for the current user (authenticated by the src CLI's access token, if any):
12+
List settings for the current user (authenticated by the src CLI's access token, if any):
1313
1414
$ src config list
1515
16-
List configuration settings for the user with username alice:
16+
List settings for the user with username alice:
1717
1818
$ src config list -subject=$(src users get -f '{{.ID}}' -username=alice)
1919
@@ -26,7 +26,7 @@ Examples:
2626
fmt.Println(usage)
2727
}
2828
var (
29-
subjectFlag = flagSet.String("subject", "", "The ID of the configuration subject whose configuration to list. (default: authenticated user)")
29+
subjectFlag = flagSet.String("subject", "", "The ID of the settings subject whose settings to list. (default: authenticated user)")
3030
formatFlag = flagSet.String("f", "", `Format for the output, using the syntax of Go package text/template. (e.g. "{{.|json}}")`)
3131
apiFlags = newAPIFlags(flagSet)
3232
)
@@ -44,7 +44,7 @@ Examples:
4444
// Set default here instead of in flagSet.String because it is very long and makes the usage message ugly.
4545
formatStr = `{{range .Subjects -}}
4646
# {{.SettingsURL}}:{{with .LatestSettings}}
47-
{{.Configuration.Contents}}
47+
{{.Contents}}
4848
{{- else}} (empty){{- end}}
4949
{{end}}`
5050
}
@@ -56,28 +56,28 @@ Examples:
5656
var query string
5757
var queryVars map[string]interface{}
5858
if *subjectFlag == "" {
59-
query = viewerConfigurationQuery
59+
query = viewerSettingsQuery
6060
} else {
61-
query = configurationSubjectCascadeQuery
61+
query = settingsSubjectCascadeQuery
6262
queryVars = map[string]interface{}{
6363
"subject": nullString(*subjectFlag),
6464
}
6565
}
6666

6767
var result struct {
68-
ViewerConfiguration *ConfigurationCascade
69-
ConfigurationSubject *ConfigurationSubject
68+
ViewerSettings *SettingsCascade
69+
SettingsSubject *SettingsSubject
7070
}
7171
return (&apiRequest{
7272
query: query,
7373
vars: queryVars,
7474
result: &result,
7575
done: func() error {
76-
var cascade *ConfigurationCascade
77-
if result.ViewerConfiguration != nil {
78-
cascade = result.ViewerConfiguration
79-
} else if result.ConfigurationSubject != nil {
80-
cascade = &result.ConfigurationSubject.ConfigurationCascade
76+
var cascade *SettingsCascade
77+
if result.ViewerSettings != nil {
78+
cascade = result.ViewerSettings
79+
} else if result.SettingsSubject != nil {
80+
cascade = &result.SettingsSubject.SettingsCascade
8181
}
8282
return execTemplate(tmpl, cascade)
8383
},

0 commit comments

Comments
 (0)