VOL-2474 Add bash completion to alarm commands
Change-Id: Ia0173fc5ffa604f5bee4c50105bd71864e9d102c
diff --git a/VERSION b/VERSION
index 8cbf02c..43b2961 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.0.12
+0.0.13
diff --git a/internal/bbsimctl/commands/alarms.go b/internal/bbsimctl/commands/alarms.go
index 3e3efec..eb4813c 100755
--- a/internal/bbsimctl/commands/alarms.go
+++ b/internal/bbsimctl/commands/alarms.go
@@ -33,6 +33,8 @@
DEFAULT_ALARM_LIST_FORMAT = "table{{ .Name }}"
)
+type AlarmNameString string
+
type AlarmListOutput struct {
Name string
}
@@ -40,16 +42,16 @@
type AlarmRaise struct {
Parameters []string `short:"p" description:"Additional Alarm Parameter in name=value form"`
Args struct {
- Name string
- SerialNumber string
+ Name AlarmNameString
+ SerialNumber OnuSnString
} `positional-args:"yes" required:"yes"`
}
type AlarmClear struct {
Parameters []string `short:"p" description:"Additional Alarm Parameter in name=value form"`
Args struct {
- Name string
- SerialNumber string
+ Name AlarmNameString
+ SerialNumber OnuSnString
} `positional-args:"yes" required:"yes"`
}
@@ -111,7 +113,7 @@
}
func (o *AlarmRaise) Execute(args []string) error {
- alarmType, err := alarmNameToEnum(o.Args.Name)
+ alarmType, err := alarmNameToEnum(string(o.Args.Name))
if err != nil {
return err
}
@@ -123,7 +125,7 @@
defer cancel()
req := pb.AlarmRequest{AlarmType: *alarmType,
- SerialNumber: o.Args.SerialNumber,
+ SerialNumber: string(o.Args.SerialNumber),
Status: "on"}
err = addParameters(o.Parameters, &req)
@@ -143,7 +145,7 @@
}
func (o *AlarmClear) Execute(args []string) error {
- alarmType, err := alarmNameToEnum(o.Args.Name)
+ alarmType, err := alarmNameToEnum(string(o.Args.Name))
if err != nil {
return err
}
@@ -155,7 +157,7 @@
defer cancel()
req := pb.AlarmRequest{AlarmType: *alarmType,
- SerialNumber: o.Args.SerialNumber,
+ SerialNumber: string(o.Args.SerialNumber),
Status: "off"}
err = addParameters(o.Parameters, &req)
@@ -186,3 +188,14 @@
tableFormat.Execute(os.Stdout, true, alarmNames)
return nil
}
+
+func (onuSn *AlarmNameString) Complete(match string) []flags.Completion {
+ list := make([]flags.Completion, 0)
+ for k := range AlarmNameMap {
+ if strings.HasPrefix(k, match) {
+ list = append(list, flags.Completion{Item: k})
+ }
+ }
+
+ return list
+}