Skip to content

Commit

Permalink
refactor: update mobius server cli
Browse files Browse the repository at this point in the history
  • Loading branch information
pyadav committed Jan 31, 2024
1 parent e17a44a commit d5226bb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
26 changes: 21 additions & 5 deletions mobius/cmd/cli.go
Expand Up @@ -5,13 +5,29 @@ import (
"github.com/spf13/cobra"
)

const Description = `
███▄ ▄███▓ ▒█████ ▄▄▄▄ ██▓ █ ██ ██████
▓██▒▀█▀ ██▒▒██▒ ██▒▓█████▄ ▓██▒ ██ ▓██▒▒██ ▒
▓██ ▓██░▒██░ ██▒▒██▒ ▄██▒██▒▓██ ▒██░░ ▓██▄
▒██ ▒██ ▒██ ██░▒██░█▀ ░██░▓▓█ ░██░ ▒ ██▒
▒██▒ ░██▒░ ████▓▒░░▓█ ▀█▓░██░▒▒█████▓ ▒██████▒▒
░ ▒░ ░ ░░ ▒░▒░▒░ ░▒▓███▀▒░▓ ░▒▓▒ ▒ ▒ ▒ ▒▓▒ ▒ ░
░ ░ ░ ░ ▒ ▒░ ▒░▒ ░ ▒ ░░░▒░ ░ ░ ░ ░▒ ░ ░
░ ░ ░ ░ ░ ▒ ░ ░ ▒ ░ ░░░ ░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░
🌈 Mobius is an open-source, lightweight, high-performance ai studio gateway
`

func New(cliConfig *Config) *cobra.Command {
cmd := &cobra.Command{
Use: "mobius <command> <subcommand> [flags]",
Short: "🌈 Mobius is an open-source, lightweight, high-performance ai studio gateway",
Long: heredoc.Doc(`
Mobius is an open-source, lightweight, high-performance ai studio gateway.
`),
Use: "mobius <command> <subcommand> [flags]",
Short: "🌈 Mobius is an open-source, lightweight, high-performance ai studio gateway",
Long: heredoc.Doc(Description),
SilenceUsage: true,
SilenceErrors: true,
}
Expand Down
25 changes: 25 additions & 0 deletions mobius/cmd/serve.go
@@ -0,0 +1,25 @@
package cmd

import (
"context"
"os/signal"
"syscall"

"github.com/missingstudio/studio/backend/config"
"github.com/missingstudio/studio/backend/pkg/server"
"github.com/missingstudio/studio/common/logger"
)

func Serve(cfg *config.Config) error {
logger := logger.New(cfg.LogFormatJson, nil)

ctx, cancelFunc := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancelFunc()

if err := server.Serve(ctx, logger, cfg); err != nil {
logger.Error("error starting server", "error", err)
return err
}

return nil
}
17 changes: 1 addition & 16 deletions mobius/cmd/server.go
@@ -1,15 +1,10 @@
package cmd

import (
"context"
"fmt"
"os/signal"
"syscall"

"github.com/MakeNowJust/heredoc"
"github.com/missingstudio/studio/backend/config"
"github.com/missingstudio/studio/backend/pkg/server"
"github.com/missingstudio/studio/common/logger"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -66,17 +61,7 @@ func serverStartCommand() *cobra.Command {
if err != nil {
panic(err)
}

logger := logger.New(appConfig.LogFormatJson, nil)

ctx, cancelFunc := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancelFunc()

if err = server.Serve(ctx, logger, appConfig); err != nil {
logger.Error("error starting server", "error", err)
return err
}
return nil
return Serve(appConfig)
},
}

Expand Down
1 change: 1 addition & 0 deletions mobius/main.go
Expand Up @@ -7,6 +7,7 @@ import (
)

func main() {
// Cli config to connect with GRPC server
cliConfig, err := cmd.LoadConfig()
if err != nil {
cliConfig = &cmd.Config{}
Expand Down

0 comments on commit d5226bb

Please sign in to comment.