mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-08-07 15:26:26 +00:00
55c19ca6b5
* Refactor CLI commands to use CLI struct Introduced a CLI struct to encapsulate dependencies such as agentSDK and managerSDK previously passed to command constructors. This shift towards a more object-oriented approach simplifies command creation and enhances code readability. CLI-related commands are now methods on the CLI struct, accessing shared services directly, which streamlines the setup of CLI command hierarchies and reduces the need to pass dependencies around. Removed the OpenAPI specification file as it was likely deemed obsolete or no longer necessary to be included with the CLI binary, suggesting a possible shift in how the API is managed or documented. Lastly, the main application now sets up two distinct command groups for 'agent' and 'manager', with respective commands organized under them, making the CLI tool's structure more intuitive for users. Signed-off-by: SammyOina <sammyoina@gmail.com> * fix ci Signed-off-by: SammyOina <sammyoina@gmail.com> --------- Signed-off-by: SammyOina <sammyoina@gmail.com>
35 lines
828 B
Go
35 lines
828 B
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package cli
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
const resultFilePath = "result.bin"
|
|
|
|
func (cli *CLI) NewResultsCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "result",
|
|
Short: "Retrieve computation result file",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
log.Println("Retrieving computation result file")
|
|
|
|
result, err := cli.agentSDK.Result(cmd.Context(), args[0])
|
|
if err != nil {
|
|
log.Fatalf("Error retrieving computation result: %v", err)
|
|
}
|
|
|
|
if err := os.WriteFile(resultFilePath, result, 0o644); err != nil {
|
|
log.Fatalf("Error saving computation result to %s: %v", resultFilePath, err)
|
|
}
|
|
|
|
log.Println("Computation result retrieved and saved successfully!")
|
|
},
|
|
}
|
|
}
|