config: Add advanced section to the config editor
This commit is contained in:
parent
d046402d80
commit
4d7d240c12
1 changed files with 39 additions and 24 deletions
|
@ -930,6 +930,40 @@ func NewRemoteName() (name string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// editOptions edits the options. If new is true then it just allows
|
||||||
|
// entry and doesn't show any old values.
|
||||||
|
func editOptions(ri *fs.RegInfo, name string, new bool) {
|
||||||
|
hasAdvanced := false
|
||||||
|
for _, advanced := range []bool{false, true} {
|
||||||
|
if advanced {
|
||||||
|
if !hasAdvanced {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
fmt.Printf("Edit advanced config? (y/n)\n")
|
||||||
|
if !Confirm() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, option := range ri.Options {
|
||||||
|
hasAdvanced = hasAdvanced || option.Advanced
|
||||||
|
if option.Advanced != advanced {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
subProvider := getConfigData().MustValue(name, fs.ConfigProvider, "")
|
||||||
|
if matchProvider(option.Provider, subProvider) {
|
||||||
|
if !new {
|
||||||
|
fmt.Printf("Value %q = %q\n", option.Name, FileGet(name, option.Name))
|
||||||
|
fmt.Printf("Edit? (y/n)>\n")
|
||||||
|
if !Confirm() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FileSet(name, option.Name, ChooseOption(&option, name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewRemote make a new remote from its name
|
// NewRemote make a new remote from its name
|
||||||
func NewRemote(name string) {
|
func NewRemote(name string) {
|
||||||
var (
|
var (
|
||||||
|
@ -937,6 +971,8 @@ func NewRemote(name string) {
|
||||||
ri *fs.RegInfo
|
ri *fs.RegInfo
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Set the type first
|
||||||
for {
|
for {
|
||||||
newType = ChooseOption(fsOption(), name)
|
newType = ChooseOption(fsOption(), name)
|
||||||
ri, err = fs.Find(newType)
|
ri, err = fs.Find(newType)
|
||||||
|
@ -947,12 +983,8 @@ func NewRemote(name string) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
getConfigData().SetValue(name, "type", newType)
|
getConfigData().SetValue(name, "type", newType)
|
||||||
for _, option := range ri.Options {
|
|
||||||
subProvider := getConfigData().MustValue(name, fs.ConfigProvider, "")
|
editOptions(ri, name, true)
|
||||||
if matchProvider(option.Provider, subProvider) {
|
|
||||||
FileSet(name, option.Name, ChooseOption(&option, name))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
RemoteConfig(name)
|
RemoteConfig(name)
|
||||||
if OkRemote(name) {
|
if OkRemote(name) {
|
||||||
SaveConfig()
|
SaveConfig()
|
||||||
|
@ -965,25 +997,8 @@ func NewRemote(name string) {
|
||||||
func EditRemote(ri *fs.RegInfo, name string) {
|
func EditRemote(ri *fs.RegInfo, name string) {
|
||||||
ShowRemote(name)
|
ShowRemote(name)
|
||||||
fmt.Printf("Edit remote\n")
|
fmt.Printf("Edit remote\n")
|
||||||
subProvider := getConfigData().MustValue(name, fs.ConfigProvider, "")
|
|
||||||
for {
|
for {
|
||||||
for _, option := range ri.Options {
|
editOptions(ri, name, false)
|
||||||
key := option.Name
|
|
||||||
value := FileGet(name, key)
|
|
||||||
if !matchProvider(option.Provider, subProvider) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
fmt.Printf("Value %q = %q\n", key, value)
|
|
||||||
fmt.Printf("Edit? (y/n)>\n")
|
|
||||||
if Confirm() {
|
|
||||||
newValue := ChooseOption(&option, name)
|
|
||||||
getConfigData().SetValue(name, key, newValue)
|
|
||||||
// Update subProvider if it changed
|
|
||||||
if key == fs.ConfigProvider {
|
|
||||||
subProvider = newValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if OkRemote(name) {
|
if OkRemote(name) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue