mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-14 17:16:41 +02:00
Add general purpose config-add and config-delete commands for string configs
This commit is contained in:
parent
10d26fa407
commit
bedb8ebb39
66
hishtory.go
66
hishtory.go
@ -150,13 +150,19 @@ func main() {
|
|||||||
vals := os.Args[3:]
|
vals := os.Args[3:]
|
||||||
config.DisplayedColumns = vals
|
config.DisplayedColumns = vals
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
case "custom-columns":
|
||||||
|
log.Fatalf("Please use config-add and config-delete to interact with custom-columns")
|
||||||
default:
|
default:
|
||||||
log.Fatalf("Unrecognized config key: %s", key)
|
log.Fatalf("Unrecognized config key: %s", key)
|
||||||
}
|
}
|
||||||
case "add-custom-column":
|
case "config-add":
|
||||||
// TODO: implement a way of deleting a custom column
|
ctx := hctx.MakeContext()
|
||||||
columnName := os.Args[2]
|
config := hctx.GetConf(ctx)
|
||||||
command := os.Args[3]
|
key := os.Args[2]
|
||||||
|
switch key {
|
||||||
|
case "custom-columns":
|
||||||
|
columnName := os.Args[3]
|
||||||
|
command := os.Args[4]
|
||||||
ctx := hctx.MakeContext()
|
ctx := hctx.MakeContext()
|
||||||
config := hctx.GetConf(ctx)
|
config := hctx.GetConf(ctx)
|
||||||
if config.CustomColumns == nil {
|
if config.CustomColumns == nil {
|
||||||
@ -164,6 +170,58 @@ func main() {
|
|||||||
}
|
}
|
||||||
config.CustomColumns = append(config.CustomColumns, hctx.CustomColumnDefinition{ColumnName: columnName, ColumnCommand: command})
|
config.CustomColumns = append(config.CustomColumns, hctx.CustomColumnDefinition{ColumnName: columnName, ColumnCommand: command})
|
||||||
lib.CheckFatalError(hctx.SetConfig(config))
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
case "displayed-columns":
|
||||||
|
vals := os.Args[3:]
|
||||||
|
config.DisplayedColumns = append(config.DisplayedColumns, vals...)
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
default:
|
||||||
|
log.Fatalf("Unrecognized config key: %s", key)
|
||||||
|
}
|
||||||
|
case "config-delete":
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
key := os.Args[2]
|
||||||
|
switch key {
|
||||||
|
case "custom-columns":
|
||||||
|
columnName := os.Args[2]
|
||||||
|
ctx := hctx.MakeContext()
|
||||||
|
config := hctx.GetConf(ctx)
|
||||||
|
if config.CustomColumns == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
newColumns := make([]hctx.CustomColumnDefinition, 0)
|
||||||
|
deletedColumns := false
|
||||||
|
for _, c := range config.CustomColumns {
|
||||||
|
if c.ColumnName != columnName {
|
||||||
|
newColumns = append(newColumns, c)
|
||||||
|
deletedColumns = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !deletedColumns {
|
||||||
|
log.Fatalf("Did not find a column with name %#v to delete (current columns = %#v)", columnName, config.CustomColumns)
|
||||||
|
}
|
||||||
|
config.CustomColumns = newColumns
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
case "displayed-columns":
|
||||||
|
deletedColumns := os.Args[3:]
|
||||||
|
newColumns := make([]string, 0)
|
||||||
|
for _, c := range config.DisplayedColumns {
|
||||||
|
isDeleted := false
|
||||||
|
for _, d := range deletedColumns {
|
||||||
|
if c == d {
|
||||||
|
isDeleted = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isDeleted {
|
||||||
|
newColumns = append(newColumns, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.DisplayedColumns = newColumns
|
||||||
|
lib.CheckFatalError(hctx.SetConfig(config))
|
||||||
|
default:
|
||||||
|
log.Fatalf("Unrecognized config key: %s", key)
|
||||||
|
}
|
||||||
|
|
||||||
case "reupload":
|
case "reupload":
|
||||||
// Purposefully undocumented since this command is generally not necessary to run
|
// Purposefully undocumented since this command is generally not necessary to run
|
||||||
lib.CheckFatalError(lib.Reupload(hctx.MakeContext()))
|
lib.CheckFatalError(lib.Reupload(hctx.MakeContext()))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user