diag.go 486 Bytes
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4
package commands

import (
	"encoding/json"
5
	"errors"
Jeromy's avatar
Jeromy committed
6 7 8 9 10 11 12
	"io"
	"time"

	"github.com/jbenet/go-ipfs/core"
)

func Diag(n *core.IpfsNode, args []string, opts map[string]interface{}, out io.Writer) error {
13 14 15
	if n.Diagnostics == nil {
		return errors.New("Cannot run diagnostic in offline mode!")
	}
Jeromy's avatar
Jeromy committed
16 17 18 19 20 21 22 23 24 25 26
	info, err := n.Diagnostics.GetDiagnostic(time.Second * 20)
	if err != nil {
		return err
	}
	enc := json.NewEncoder(out)
	err = enc.Encode(info)
	if err != nil {
		return err
	}
	return nil
}