-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor kit dev flags to subcommands
Replace --stop and --logs flags for kit dev with subcommands: * kit dev start -> start the server * kit dev stop -> stop a running server * kit dev logs -> print logs from last run
- Loading branch information
Showing
4 changed files
with
205 additions
and
87 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
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,77 @@ | ||
// Copyright 2024 The KitOps Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package dev | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"kitops/pkg/lib/constants" | ||
"kitops/pkg/lib/filesystem" | ||
"kitops/pkg/output" | ||
) | ||
|
||
type DevBaseOptions struct { | ||
configHome string | ||
} | ||
|
||
func (opts *DevBaseOptions) complete(ctx context.Context, args []string) error { | ||
configHome, ok := ctx.Value(constants.ConfigKey{}).(string) | ||
if !ok { | ||
return fmt.Errorf("default config path not set on command context") | ||
} | ||
opts.configHome = configHome | ||
return nil | ||
} | ||
|
||
type DevStartOptions struct { | ||
DevBaseOptions | ||
host string | ||
port int | ||
modelFile string | ||
contextDir string | ||
} | ||
|
||
func (opts *DevStartOptions) complete(ctx context.Context, args []string) error { | ||
if err := opts.DevBaseOptions.complete(ctx, args); err != nil { | ||
return err | ||
} | ||
|
||
opts.contextDir = "" | ||
if len(args) == 1 { | ||
opts.contextDir = args[0] | ||
} | ||
if opts.modelFile == "" { | ||
foundKitfile, err := filesystem.FindKitfileInPath(opts.contextDir) | ||
if err != nil { | ||
return err | ||
} | ||
opts.modelFile = foundKitfile | ||
} | ||
if opts.host == "" { | ||
opts.host = "127.0.0.1" | ||
} | ||
|
||
if opts.port == 0 { | ||
availPort, err := findAvailablePort() | ||
if err != nil { | ||
output.Fatalf("Invalid arguments: %s", err) | ||
return err | ||
} | ||
opts.port = availPort | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2024 The KitOps Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package dev | ||
|
||
const ( | ||
devShortDesc = "Run models locally (experimental)" | ||
devLongDesc = "Start a local server and interact with a model in the browser" | ||
devExample = "kit dev start" | ||
|
||
devStartShortDesc = "Start development server (experimental)" | ||
devStartLongDesc = `Start development server (experimental) from a modelkit | ||
Start a development server for an unpacked modelkit, using a context directory | ||
that includes the model and a kitfile. | ||
` | ||
devStartExample = `# Serve the model located in the current directory | ||
kit dev start | ||
# Serve the modelkit in ./my-model on port 8080 | ||
kit dev start ./my-model --port 8080 | ||
` | ||
|
||
devStopShortDesc = "Stop development server" | ||
devStopLongDesc = "Stop the development server if it is running" | ||
|
||
devLogsShortDesc = "View logs for development server" | ||
devLogsLongDesc = `Print any logs output by the development server. | ||
If the development server is currently running, the logs for this server will | ||
be printed. If it is stopped, the logs for the previous run of the server, if | ||
available, will be printed instead. | ||
` | ||
) |