package parsers import ( "regexp" "github.rackspace.com/gorax/tools/util" ) // used with 'show script all' var ( scriptsRe = regexp.MustCompile(`\s+(\d+)\s+(\S+)\s+(\S+)\s*\n`) totalInUseRe = regexp.MustCompile(`Total\s+Scripts\s+In\s+Use:\s+(\d+)`) ) type ( // AdxScripts is a listing of all ADX scripts on the box AdxScripts struct { Script []AdxScript `json:"scripts"` TotalInUse string `json:"total in use"` } // AdxScript parsed data for a single ADX script AdxScript struct { Index string `json:"index"` Name string `json:"name"` InUse string `json:"in use"` } ) // Parse method is used to implement type population of a given string // using parsers to populate the method receiver. func (a *AdxScripts) Parse(s string) { for _, v := range scriptsRe.FindAllStringSubmatch(s, -1) { a.Script = append(a.Script, AdxScript{Index: v[1], Name: v[2], InUse: v[3]}) } a.TotalInUse = util.RegexpFindString(totalInUseRe, s) }