66 "context"
77 "fmt"
88
9- "github.com/onkernel/hypeman-cli/pkg/jsonflag"
109 "github.com/onkernel/hypeman-go"
1110 "github.com/onkernel/hypeman-go/option"
1211 "github.com/tidwall/gjson"
@@ -17,13 +16,9 @@ var imagesCreate = cli.Command{
1716 Name : "create" ,
1817 Usage : "Pull and convert OCI image" ,
1918 Flags : []cli.Flag {
20- & jsonflag. JSONStringFlag {
19+ & cli. StringFlag {
2120 Name : "name" ,
2221 Usage : "OCI image reference (e.g., docker.io/library/nginx:latest)" ,
23- Config : jsonflag.JSONConfig {
24- Kind : jsonflag .Body ,
25- Path : "name" ,
26- },
2722 },
2823 },
2924 Action : handleImagesCreate ,
@@ -63,17 +58,22 @@ var imagesDelete = cli.Command{
6358}
6459
6560func handleImagesCreate (ctx context.Context , cmd * cli.Command ) error {
66- cc := getAPICommandContext ( cmd )
61+ client := hypeman . NewClient ( getDefaultRequestOptions ( cmd ) ... )
6762 unusedArgs := cmd .Args ().Slice ()
6863 if len (unusedArgs ) > 0 {
6964 return fmt .Errorf ("Unexpected extra arguments: %v" , unusedArgs )
7065 }
7166 params := hypeman.ImageNewParams {}
67+ if err := unmarshalStdinWithFlags (cmd , map [string ]string {
68+ "name" : "name" ,
69+ }, & params ); err != nil {
70+ return err
71+ }
7272 var res []byte
73- _ , err := cc . client .Images .New (
73+ _ , err := client .Images .New (
7474 ctx ,
7575 params ,
76- option .WithMiddleware (cc . AsMiddleware ( )),
76+ option .WithMiddleware (debugMiddleware ( cmd . Bool ( "debug" ) )),
7777 option .WithResponseBodyInto (& res ),
7878 )
7979 if err != nil {
@@ -87,7 +87,7 @@ func handleImagesCreate(ctx context.Context, cmd *cli.Command) error {
8787}
8888
8989func handleImagesRetrieve (ctx context.Context , cmd * cli.Command ) error {
90- cc := getAPICommandContext ( cmd )
90+ client := hypeman . NewClient ( getDefaultRequestOptions ( cmd ) ... )
9191 unusedArgs := cmd .Args ().Slice ()
9292 if ! cmd .IsSet ("name" ) && len (unusedArgs ) > 0 {
9393 cmd .Set ("name" , unusedArgs [0 ])
@@ -97,10 +97,10 @@ func handleImagesRetrieve(ctx context.Context, cmd *cli.Command) error {
9797 return fmt .Errorf ("Unexpected extra arguments: %v" , unusedArgs )
9898 }
9999 var res []byte
100- _ , err := cc . client .Images .Get (
100+ _ , err := client .Images .Get (
101101 ctx ,
102102 cmd .Value ("name" ).(string ),
103- option .WithMiddleware (cc . AsMiddleware ( )),
103+ option .WithMiddleware (debugMiddleware ( cmd . Bool ( "debug" ) )),
104104 option .WithResponseBodyInto (& res ),
105105 )
106106 if err != nil {
@@ -114,15 +114,15 @@ func handleImagesRetrieve(ctx context.Context, cmd *cli.Command) error {
114114}
115115
116116func handleImagesList (ctx context.Context , cmd * cli.Command ) error {
117- cc := getAPICommandContext ( cmd )
117+ client := hypeman . NewClient ( getDefaultRequestOptions ( cmd ) ... )
118118 unusedArgs := cmd .Args ().Slice ()
119119 if len (unusedArgs ) > 0 {
120120 return fmt .Errorf ("Unexpected extra arguments: %v" , unusedArgs )
121121 }
122122 var res []byte
123- _ , err := cc . client .Images .List (
123+ _ , err := client .Images .List (
124124 ctx ,
125- option .WithMiddleware (cc . AsMiddleware ( )),
125+ option .WithMiddleware (debugMiddleware ( cmd . Bool ( "debug" ) )),
126126 option .WithResponseBodyInto (& res ),
127127 )
128128 if err != nil {
@@ -136,7 +136,7 @@ func handleImagesList(ctx context.Context, cmd *cli.Command) error {
136136}
137137
138138func handleImagesDelete (ctx context.Context , cmd * cli.Command ) error {
139- cc := getAPICommandContext ( cmd )
139+ client := hypeman . NewClient ( getDefaultRequestOptions ( cmd ) ... )
140140 unusedArgs := cmd .Args ().Slice ()
141141 if ! cmd .IsSet ("name" ) && len (unusedArgs ) > 0 {
142142 cmd .Set ("name" , unusedArgs [0 ])
@@ -145,9 +145,9 @@ func handleImagesDelete(ctx context.Context, cmd *cli.Command) error {
145145 if len (unusedArgs ) > 0 {
146146 return fmt .Errorf ("Unexpected extra arguments: %v" , unusedArgs )
147147 }
148- return cc . client .Images .Delete (
148+ return client .Images .Delete (
149149 ctx ,
150150 cmd .Value ("name" ).(string ),
151- option .WithMiddleware (cc . AsMiddleware ( )),
151+ option .WithMiddleware (debugMiddleware ( cmd . Bool ( "debug" ) )),
152152 )
153153}
0 commit comments