44 "context"
55 "fmt"
66 "os"
7+ "sort"
78 "strings"
89
910 exocmd "github.com/exoscale/cli/cmd"
@@ -18,14 +19,15 @@ type DeploymentCreateCmd struct {
1819
1920 _ bool `cli-cmd:"create"`
2021
21- Name string `cli-arg:"# " cli-usage:"NAME"`
22+ Name string `cli-arg:"? " cli-usage:"NAME"`
2223 GPUType string `cli-flag:"gpu-type" cli-usage:"GPU type family (e.g., gpua5000, gpu3080ti)"`
2324 GPUCount int64 `cli-flag:"gpu-count" cli-usage:"Number of GPUs (1-8)"`
2425 Replicas int64 `cli-flag:"replicas" cli-usage:"Number of replicas (>=1)"`
2526
2627 ModelID string `cli-flag:"model-id" cli-usage:"Model ID (UUID)"`
2728 ModelName string `cli-flag:"model-name" cli-usage:"Model name (as created)"`
2829 InferenceEngineParameters string `cli-flag:"inference-engine-params" cli-usage:"Space-separated inference engine server CLI arguments (e.g., \"--gpu-memory-usage=0.8 --max-tokens=4096\")"`
30+ InferenceEngineHelp bool `cli-flag:"inference-engine-parameter-help" cli-usage:"Show inference engine parameters help"`
2931 Zone v3.ZoneName `cli-short:"z" cli-usage:"zone"`
3032}
3133
@@ -38,13 +40,88 @@ func (c *DeploymentCreateCmd) CmdPreRun(cmd *cobra.Command, args []string) error
3840 exocmd .CmdSetZoneFlagFromDefault (cmd )
3941 return exocmd .CliCommandDefaultPreRun (c , cmd , args )
4042}
43+ func (c * DeploymentCreateCmd ) showInferenceEngineParameterHelp (ctx context.Context , client * v3.Client ) error {
44+ resp , err := client .GetInferenceEngineHelp (ctx )
45+ if err != nil {
46+ return err
47+ }
48+
49+ sections := make (map [string ][]v3.InferenceEngineParameterEntry )
50+ var sectionNames []string
51+ for _ , p := range resp .Parameters {
52+ if _ , ok := sections [p .Section ]; ! ok {
53+ sectionNames = append (sectionNames , p .Section )
54+ }
55+ sections [p .Section ] = append (sections [p .Section ], p )
56+ }
57+ sort .Strings (sectionNames )
58+
59+ for i , section := range sectionNames {
60+ if i > 0 {
61+ fmt .Println ()
62+ }
63+ fmt .Printf ("%s:\n " , section )
64+ for _ , p := range sections [section ] {
65+ flags := strings .Join (p .Flags , ", " )
66+ if p .Type != "boolean" && p .Type != "enum" {
67+ flags += " " + strings .ToUpper (strings .ReplaceAll (p .Name , "-" , "_" ))
68+ }
69+
70+ fmt .Printf (" %s\n " , flags )
71+
72+ desc := p .Description
73+ if p .Default != "" {
74+ // The description in example sometimes already includes default, but the example output
75+ // shows (default: ...) at the end.
76+ if ! strings .Contains (desc , fmt .Sprintf ("(default: %s)" , p .Default )) {
77+ desc += fmt .Sprintf (" (default: %s)" , p .Default )
78+ }
79+ }
80+
81+ // Simple wrapping
82+ words := strings .Fields (desc )
83+ if len (words ) > 0 {
84+ line := " "
85+ for _ , word := range words {
86+ if len (line )+ len (word ) > 160 {
87+ fmt .Println (line )
88+ line = " " + word
89+ } else {
90+ if line == " " {
91+ line += word
92+ } else {
93+ line += " " + word
94+ }
95+ }
96+ }
97+ fmt .Println (line )
98+ }
99+ }
100+ }
101+
102+ return nil
103+ }
104+
41105func (c * DeploymentCreateCmd ) CmdRun (_ * cobra.Command , _ []string ) error {
42106 ctx := exocmd .GContext
107+
108+ if c .InferenceEngineHelp {
109+ client , err := exocmd .SwitchClientZoneV3 (ctx , globalstate .EgoscaleV3Client , c .Zone )
110+ if err != nil {
111+ return err
112+ }
113+ return c .showInferenceEngineParameterHelp (ctx , client )
114+ }
115+
43116 client , err := exocmd .SwitchClientZoneV3 (ctx , globalstate .EgoscaleV3Client , c .Zone )
44117 if err != nil {
45118 return err
46119 }
47120
121+ if c .Name == "" {
122+ return fmt .Errorf ("NAME is required" )
123+ }
124+
48125 if c .GPUType == "" || c .GPUCount == 0 {
49126 return fmt .Errorf ("--gpu-type and --gpu-count are required" )
50127 }
0 commit comments