Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

streamline install #44

Merged
merged 11 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build: mdai
mdai:
rm -f mdai
go mod vendor
CGO_ENABLED=0 go build -ldflags="-X 'github.com/decisiveai/mdai-cli/cmd.Version=`git describe --tags --abbrev=0`' -X 'github.com/decisiveai/mdai-cli/cmd.GitSha=`git rev-parse HEAD`' -X 'github.com/decisiveai/mdai-cli/cmd.BuildTime=`date`'" -o mdai main.go
CGO_ENABLED=0 go build -ldflags="-w -s -X 'github.com/decisiveai/mdai-cli/cmd.Version=`git describe --tags --abbrev=0`' -X 'github.com/decisiveai/mdai-cli/cmd.GitSha=`git rev-parse HEAD`' -X 'github.com/decisiveai/mdai-cli/cmd.BuildTime=`date`'" -o mdai main.go

.PHONY: docker-build
.SILENT: docker-build
Expand Down
120 changes: 0 additions & 120 deletions cmd/demo.go

This file was deleted.

18 changes: 6 additions & 12 deletions cmd/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,37 @@ package cmd

import (
"fmt"
"slices"
"strings"

"github.com/decisiveai/mdai-cli/internal/operator"
"github.com/spf13/cobra"
)

func NewDisableCommand() *cobra.Command {
flags := disableFlags{}
cmd := &cobra.Command{
GroupID: "configuration",
Use: "disable -m|--module MODULE",
Short: "disable a module",
Long: `disable a module`,
Example: ` mdai disable --module datalyzer`,
PreRunE: func(cmd *cobra.Command, _ []string) error {
module, _ := cmd.Flags().GetString("module")
if module != "" && !slices.Contains(SupportedModules, module) {
return fmt.Errorf(`module "%s" is not supported for disabling`, module)
}
return nil
},
RunE: func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
module, _ := cmd.Flags().GetString("module")

switch module {
switch flags.module {
case "datalyzer":
if err := operator.DisableDatalyzer(ctx); err != nil {
return err
}
default:
return fmt.Errorf(`module "%s" is not supported for disabling`, flags.module)
}

fmt.Printf("%s module disabled successfully.\n", module)
fmt.Printf("%s module disabled successfully.\n", flags.module)
return nil
},
}
cmd.Flags().String("module", "", "module to disable ["+strings.Join(SupportedModules, ", ")+"]")
cmd.Flags().StringVar(&flags.module, "module", "", "module to disable ["+strings.Join(supportedModules(), ", ")+"]")

_ = cmd.MarkFlagRequired("module")

Expand Down
5 changes: 5 additions & 0 deletions cmd/disable_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cmd

type disableFlags struct {
module string
}
29 changes: 14 additions & 15 deletions cmd/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,36 @@ import (
)

func NewDocsCommand() *cobra.Command {
flags := docsFlags{}
cmd := &cobra.Command{
Use: "docs",
Short: "generate documentation",
Long: ``,
RunE: func(cmd *cobra.Command, _ []string) error {
md, _ := cmd.Flags().GetBool("md")
yaml, _ := cmd.Flags().GetBool("yaml")
rst, _ := cmd.Flags().GetBool("rst")
man, _ := cmd.Flags().GetBool("man")

rootCmd, _ := NewRootCommand()
RunE: func(_ *cobra.Command, _ []string) error {
rootCmd, err := NewRootCommand()
if err != nil {
return fmt.Errorf("failed to create root command: %w", err)
}

if md {
if flags.md {
if err := doc.GenMarkdownTree(rootCmd, "docs/md"); err != nil {
return fmt.Errorf("failed to generate markdown documentation: %w", err)
}
}

if yaml {
if flags.yaml {
if err := doc.GenYamlTree(rootCmd, "docs/yaml"); err != nil {
return fmt.Errorf("failed to generate yaml documentation: %w", err)
}
}

if rst {
if flags.rst {
if err := doc.GenReSTTree(rootCmd, "docs/rst"); err != nil {
return fmt.Errorf("failed to generate rst documentation: %w", err)
}
}

if man {
if flags.man {
header := &doc.GenManHeader{
Title: "MDAI CLI",
Section: "1",
Expand All @@ -52,10 +51,10 @@ func NewDocsCommand() *cobra.Command {
return nil
},
}
cmd.Flags().Bool("yaml", false, "generate YAML documentation")
cmd.Flags().Bool("markdown", true, "generate Markdown documentation")
cmd.Flags().Bool("restructured", false, "generate ReStructuredText documentation")
cmd.Flags().Bool("man", false, "generate man page documentation")
cmd.Flags().BoolVar(&flags.yaml, "yaml", false, "generate YAML documentation")
cmd.Flags().BoolVar(&flags.md, "markdown", true, "generate Markdown documentation")
cmd.Flags().BoolVar(&flags.rst, "restructured", false, "generate ReStructuredText documentation")
cmd.Flags().BoolVar(&flags.man, "man", false, "generate man page documentation")

cmd.Flags().SetNormalizeFunc(func(_ *pflag.FlagSet, name string) pflag.NormalizedName {
switch name {
Expand Down
8 changes: 8 additions & 0 deletions cmd/docs_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cmd

type docsFlags struct {
md bool
yaml bool
rst bool
man bool
}
18 changes: 6 additions & 12 deletions cmd/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,37 @@ package cmd

import (
"fmt"
"slices"
"strings"

"github.com/decisiveai/mdai-cli/internal/operator"
"github.com/spf13/cobra"
)

func NewEnableCommand() *cobra.Command {
flags := enableFlags{}
cmd := &cobra.Command{
GroupID: "configuration",
Use: "enable -m|--module MODULE",
Short: "enable a module",
Long: `enable one of the supported modules`,
Example: ` mdai enable --module datalyzer`,
PreRunE: func(cmd *cobra.Command, _ []string) error {
module, _ := cmd.Flags().GetString("module")
if module != "" && !slices.Contains(SupportedModules, module) {
return fmt.Errorf(`module "%s" is not supported for enabling`, module)
}
return nil
},
RunE: func(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
module, _ := cmd.Flags().GetString("module")

switch module {
switch flags.module {
case "datalyzer":
if err := operator.EnableDatalyzer(ctx); err != nil {
return err
}
default:
return fmt.Errorf(`module "%s" is not supported for enabling`, flags.module)
}

fmt.Printf("%s module enabled successfully.\n", module)
fmt.Printf("%s module enabled successfully.\n", flags.module)
return nil
},
}
cmd.Flags().String("module", "", "module to enable ["+strings.Join(SupportedModules, ", ")+"]")
cmd.Flags().StringVar(&flags.module, "module", "", "module to enable ["+strings.Join(supportedModules(), ", ")+"]")
arcanez marked this conversation as resolved.
Show resolved Hide resolved

_ = cmd.MarkFlagRequired("module")

Expand Down
5 changes: 5 additions & 0 deletions cmd/enable_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cmd

type enableFlags struct {
module string
}
Loading