-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from CoopHive/hive-inspect
hive inspect
- Loading branch information
Showing
6 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package hive | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/CoopHive/coophive/pkg/inspect" | ||
optionsfactory "github.com/CoopHive/coophive/pkg/options" | ||
"github.com/CoopHive/coophive/pkg/web3" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newInspectCmd() *cobra.Command { | ||
options := optionsfactory.NewInspectOptions() | ||
runCmd := &cobra.Command{ | ||
Use: "inspect", | ||
Short: "View metadata for a previously run job.", | ||
Long: "View metadata for a previously run job.", | ||
Example: "inspect cowsay:v0.0.1 -i Message=moo", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
options, err := optionsfactory.ProcessInspectOptions(options, args) | ||
if err != nil { | ||
return err | ||
} | ||
return inspectJob(cmd, options) | ||
}, | ||
} | ||
optionsfactory.AddInspectCliFlags(runCmd, &options) | ||
return runCmd | ||
} | ||
|
||
func inspectJob(cmd *cobra.Command, options inspect.InspectOptions) error { | ||
web3SDK, err := web3.NewContractSDK(options.Web3) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("deal id: %s\n", options.DealID) | ||
|
||
dealData, err := web3SDK.Contracts.Storage.GetDeal(web3SDK.CallOpts, options.DealID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
jsonBytes, err := json.Marshal(dealData) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
jsonString := string(jsonBytes) | ||
fmt.Println(jsonString) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package inspect | ||
|
||
import "github.com/CoopHive/coophive/pkg/web3" | ||
|
||
type InspectOptions struct { | ||
Web3 web3.Web3Options | ||
DealID string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package options | ||
|
||
import ( | ||
"github.com/CoopHive/coophive/pkg/inspect" | ||
"github.com/CoopHive/coophive/pkg/system" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewInspectOptions() inspect.InspectOptions { | ||
options := inspect.InspectOptions{ | ||
Web3: GetDefaultWeb3Options(), | ||
DealID: "", | ||
} | ||
options.Web3.Service = system.JobCreatorService | ||
return options | ||
} | ||
|
||
func ProcessInspectOptions(options inspect.InspectOptions, args []string) (inspect.InspectOptions, error) { | ||
dealId := "" | ||
if len(args) == 1 { | ||
dealId = args[0] | ||
} | ||
|
||
if dealId != "" { | ||
options.DealID = dealId | ||
} | ||
newWeb3Options, err := ProcessWeb3Options(options.Web3) | ||
if err != nil { | ||
return options, err | ||
} | ||
options.Web3 = newWeb3Options | ||
|
||
return options, CheckInspectOptions(options) | ||
} | ||
|
||
func CheckInspectOptions(options inspect.InspectOptions) error { | ||
err := CheckWeb3Options(options.Web3) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// TODO validate dealID | ||
return nil | ||
} | ||
|
||
func AddInspectCliFlags(cmd *cobra.Command, options *inspect.InspectOptions) { | ||
AddWeb3CliFlags(cmd, &options.Web3) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters