Skip to content

Commit

Permalink
Convert filterid and filtertype flags to comma-separated lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
bemasher committed Oct 29, 2014
1 parent ed47c5c commit 2b055fc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
35 changes: 33 additions & 2 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ var fastMag = flag.Bool("fastmag", false, "use faster alpha max + beta min magni
var symbolLength = flag.Int("symbollength", 73, "symbol length in samples, see -help for valid lengths")

var timeLimit = flag.Duration("duration", 0, "time to run for, 0 for infinite, ex. 1h5m10s")
var meterID = flag.Uint("filterid", 0, "display only messages matching given id")
var meterType = flag.Uint("filtertype", 0, "display only messages matching given type")
var meterID UintMap
var meterType UintMap

var encoder Encoder
var format = flag.String("format", "plain", "format to write log messages in: plain, csv, json, xml or gob")
Expand All @@ -53,6 +53,12 @@ var quiet = flag.Bool("quiet", false, "suppress printing state information at st
var single = flag.Bool("single", false, "one shot execution")

func RegisterFlags() {
meterID = make(UintMap)
meterType = make(UintMap)

flag.Var(meterID, "filterid", "display only messages matching an id in a comma-separated list of ids.")
flag.Var(meterType, "filtertype", "display only messages matching a type in a comma-separated list of types.")

// Override default center frequency.
centerFreqFlag := flag.CommandLine.Lookup("centerfreq")
centerFreqString := strconv.FormatUint(CenterFreq, 10)
Expand Down Expand Up @@ -138,3 +144,28 @@ func HandleFlags() {
type Encoder interface {
Encode(interface{}) error
}

type UintMap map[uint]bool

func (m UintMap) String() (s string) {
var values []string
for k := range m {
values = append(values, strconv.FormatUint(uint64(k), 10))
}
return strings.Join(values, ",")
}

func (m UintMap) Set(value string) error {
values := strings.Split(value, ",")

for _, v := range values {
n, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return err
}

m[uint(n)] = true
}

return nil
}
4 changes: 2 additions & 2 deletions recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ func (rcvr *Receiver) Run() {
continue
}

if *meterID != 0 && uint32(*meterID) != scm.MeterID() {
if len(meterID) > 0 && !meterID[uint(scm.MeterID())] {
continue
}

if *meterType != 0 && uint8(*meterType) != scm.MeterType() {
if len(meterType) > 0 && !meterType[uint(scm.MeterType())] {
continue
}

Expand Down

0 comments on commit 2b055fc

Please sign in to comment.