Fix cscli inpsect json output (#1145)
* Fix cscli inpsect json output Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
This commit is contained in:
parent
8e3004ebb3
commit
ba71c55492
|
@ -306,11 +306,25 @@ func InspectItem(name string, objecitemType string) {
|
||||||
if hubItem == nil {
|
if hubItem == nil {
|
||||||
log.Fatalf("unable to retrieve item.")
|
log.Fatalf("unable to retrieve item.")
|
||||||
}
|
}
|
||||||
buff, err := yaml.Marshal(*hubItem)
|
var b []byte
|
||||||
if err != nil {
|
var err error
|
||||||
log.Fatalf("unable to marshal item : %s", err)
|
switch csConfig.Cscli.Output {
|
||||||
|
case "human", "raw":
|
||||||
|
b, err = yaml.Marshal(*hubItem)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("unable to marshal item : %s", err)
|
||||||
|
}
|
||||||
|
case "json":
|
||||||
|
b, err = json.MarshalIndent(*hubItem, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("unable to marshal item : %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("%s", string(buff))
|
fmt.Printf("%s", string(b))
|
||||||
|
if csConfig.Cscli.Output == "json" || csConfig.Cscli.Output == "raw" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if csConfig.Prometheus.Enabled {
|
if csConfig.Prometheus.Enabled {
|
||||||
if csConfig.Prometheus.ListenAddr == "" || csConfig.Prometheus.ListenPort == 0 {
|
if csConfig.Prometheus.ListenAddr == "" || csConfig.Prometheus.ListenPort == 0 {
|
||||||
log.Warningf("No prometheus address or port specified in '%s', can't show metrics", *csConfig.FilePath)
|
log.Warningf("No prometheus address or port specified in '%s', can't show metrics", *csConfig.FilePath)
|
||||||
|
|
|
@ -31,8 +31,8 @@ var HubBranch = "master"
|
||||||
var HubIndexFile = ".index.json"
|
var HubIndexFile = ".index.json"
|
||||||
|
|
||||||
type ItemVersion struct {
|
type ItemVersion struct {
|
||||||
Digest string
|
Digest string `json:"digest,omitempty"`
|
||||||
Deprecated bool
|
Deprecated bool `json:"deprecated,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemHubStatus struct {
|
type ItemHubStatus struct {
|
||||||
|
@ -47,38 +47,38 @@ type ItemHubStatus struct {
|
||||||
//Item can be : parsed, scenario, collection
|
//Item can be : parsed, scenario, collection
|
||||||
type Item struct {
|
type Item struct {
|
||||||
/*descriptive info*/
|
/*descriptive info*/
|
||||||
Type string `yaml:"type,omitempty"` //parser|postoverflows|scenario|collection(|enrich)
|
Type string `yaml:"type,omitempty" json:"type,omitempty"` //parser|postoverflows|scenario|collection(|enrich)
|
||||||
Stage string `json:"stage" yaml:"stage,omitempty,omitempty"` //Stage for parser|postoverflow : s00-raw/s01-...
|
Stage string `json:"stage,omitempty" yaml:"stage,omitempty,omitempty"` //Stage for parser|postoverflow : s00-raw/s01-...
|
||||||
Name string //as seen in .config.json, usually "author/name"
|
Name string `json:"name,omitempty"` //as seen in .config.json, usually "author/name"
|
||||||
FileName string //the filename, ie. apache2-logs.yaml
|
FileName string `json:"file_name,omitempty"` //the filename, ie. apache2-logs.yaml
|
||||||
Description string `yaml:"description,omitempty"` //as seen in .config.json
|
Description string `yaml:"description,omitempty" json:"description,omitempty"` //as seen in .config.json
|
||||||
Author string `json:"author"` //as seen in .config.json
|
Author string `json:"author,omitempty"` //as seen in .config.json
|
||||||
References []string `yaml:"references,omitempty"` //as seen in .config.json
|
References []string `yaml:"references,omitempty" json:"references,omitempty"` //as seen in .config.json
|
||||||
BelongsToCollections []string `yaml:"belongs_to_collections,omitempty"` /*if it's part of collections, track name here*/
|
BelongsToCollections []string `yaml:"belongs_to_collections,omitempty" json:"belongs_to_collections,omitempty"` /*if it's part of collections, track name here*/
|
||||||
|
|
||||||
/*remote (hub) infos*/
|
/*remote (hub) infos*/
|
||||||
RemoteURL string `yaml:"remoteURL,omitempty"` //the full remote uri of file in http
|
RemoteURL string `yaml:"remoteURL,omitempty" json:"remoteURL,omitempty"` //the full remote uri of file in http
|
||||||
RemotePath string `json:"path" yaml:"remote_path,omitempty"` //the path relative to git ie. /parsers/stage/author/file.yaml
|
RemotePath string `json:"path,omitempty" yaml:"remote_path,omitempty"` //the path relative to git ie. /parsers/stage/author/file.yaml
|
||||||
RemoteHash string `yaml:"hash,omitempty"` //the meow
|
RemoteHash string `yaml:"hash,omitempty" json:"hash,omitempty"` //the meow
|
||||||
Version string `json:"version"` //the last version
|
Version string `json:"version,omitempty"` //the last version
|
||||||
Versions map[string]ItemVersion `json:"versions" yaml:"-"` //the list of existing versions
|
Versions map[string]ItemVersion `json:"versions,omitempty" yaml:"-"` //the list of existing versions
|
||||||
|
|
||||||
/*local (deployed) infos*/
|
/*local (deployed) infos*/
|
||||||
LocalPath string `yaml:"local_path,omitempty"` //the local path relative to ${CFG_DIR}
|
LocalPath string `yaml:"local_path,omitempty" json:"local_path,omitempty"` //the local path relative to ${CFG_DIR}
|
||||||
//LocalHubPath string
|
//LocalHubPath string
|
||||||
LocalVersion string
|
LocalVersion string `json:"local_version,omitempty"`
|
||||||
LocalHash string //the local meow
|
LocalHash string `json:"local_hash,omitempty"` //the local meow
|
||||||
Installed bool
|
Installed bool `json:"installed,omitempty"`
|
||||||
Downloaded bool
|
Downloaded bool `json:"downloaded,omitempty"`
|
||||||
UpToDate bool
|
UpToDate bool `json:"up_to_date,omitempty"`
|
||||||
Tainted bool //has it been locally modified
|
Tainted bool `json:"tainted,omitempty"` //has it been locally modified
|
||||||
Local bool //if it's a non versioned control one
|
Local bool `json:"local,omitempty"` //if it's a non versioned control one
|
||||||
|
|
||||||
/*if it's a collection, it not a single file*/
|
/*if it's a collection, it not a single file*/
|
||||||
Parsers []string `yaml:"parsers,omitempty"`
|
Parsers []string `yaml:"parsers,omitempty" json:"parsers,omitempty"`
|
||||||
PostOverflows []string `yaml:"postoverflows,omitempty"`
|
PostOverflows []string `yaml:"postoverflows,omitempty" json:"postoverflows,omitempty"`
|
||||||
Scenarios []string `yaml:"scenarios,omitempty"`
|
Scenarios []string `yaml:"scenarios,omitempty" json:"scenarios,omitempty"`
|
||||||
Collections []string `yaml:"collections,omitempty"`
|
Collections []string `yaml:"collections,omitempty" json:"collections,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) toHubStatus() ItemHubStatus {
|
func (i *Item) toHubStatus() ItemHubStatus {
|
||||||
|
|
Loading…
Reference in a new issue