add the pm command to survey cli
use command context to store app service
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
"github.com/LazyBachelor/LazyPM/cmd/survey/tasks"
|
||||||
|
issuesCmd "github.com/LazyBachelor/LazyPM/internal/commands/issues"
|
||||||
surveyCmd "github.com/LazyBachelor/LazyPM/internal/commands/survey"
|
surveyCmd "github.com/LazyBachelor/LazyPM/internal/commands/survey"
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/repl"
|
"github.com/LazyBachelor/LazyPM/pkg/repl"
|
||||||
@@ -15,6 +16,14 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
app, cleanup, err := initializeServices(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
surveyCmd.SetApp(app)
|
||||||
|
issuesCmd.SetApp(app)
|
||||||
|
|
||||||
if err := fang.Execute(ctx, surveyCmd.RootCmd,
|
if err := fang.Execute(ctx, surveyCmd.RootCmd,
|
||||||
fang.WithColorSchemeFunc(fang.AnsiColorScheme)); err != nil {
|
fang.WithColorSchemeFunc(fang.AnsiColorScheme)); err != nil {
|
||||||
@@ -33,6 +42,7 @@ func init() {
|
|||||||
surveyCmd.RootCmd.AddCommand(surveyCmd.StatusCmd)
|
surveyCmd.RootCmd.AddCommand(surveyCmd.StatusCmd)
|
||||||
surveyCmd.RootCmd.AddCommand(surveyCmd.ListTasksCmd)
|
surveyCmd.RootCmd.AddCommand(surveyCmd.ListTasksCmd)
|
||||||
surveyCmd.RootCmd.AddCommand(surveyCmd.ListInterfacesCmd)
|
surveyCmd.RootCmd.AddCommand(surveyCmd.ListInterfacesCmd)
|
||||||
|
surveyCmd.RootCmd.AddCommand(issuesCmd.RootCmd)
|
||||||
|
|
||||||
task.RegisterTask("create_issue", func(app *service.App) task.Tasker {
|
task.RegisterTask("create_issue", func(app *service.App) task.Tasker {
|
||||||
return tasks.NewCreateIssueTask(app)
|
return tasks.NewCreateIssueTask(app)
|
||||||
|
|||||||
@@ -13,15 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func runStartCmd(cmd *cobra.Command, args []string) error {
|
func runStartCmd(cmd *cobra.Command, args []string) error {
|
||||||
|
app := surveyCmd.AppFromContext(cmd.Context())
|
||||||
interfaces := initInterfaces()
|
interfaces := initInterfaces()
|
||||||
|
surveyTasks := initTasks(app)
|
||||||
svc, cleanup, err := initializeServices(cmd.Context())
|
|
||||||
if err != nil {
|
|
||||||
return returnIfUserQuit(err, "failed to initialize services")
|
|
||||||
}
|
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
surveyTasks := initTasks(svc)
|
|
||||||
|
|
||||||
if cmd.Flags().Changed("interface") {
|
if cmd.Flags().Changed("interface") {
|
||||||
if _, ok := interfaces[surveyCmd.InterfaceType]; !ok {
|
if _, ok := interfaces[surveyCmd.InterfaceType]; !ok {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ type Flags struct {
|
|||||||
|
|
||||||
// RootCmd is the base command for the CLI application.
|
// RootCmd is the base command for the CLI application.
|
||||||
var RootCmd = &cobra.Command{
|
var RootCmd = &cobra.Command{
|
||||||
|
Use: "pm",
|
||||||
Short: "Project Management CLI",
|
Short: "Project Management CLI",
|
||||||
Long: `Project Management CLI for managing issues and tasks.`,
|
Long: `Project Management CLI for managing issues and tasks.`,
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
package surveyCmd
|
package surveyCmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RootCmd is the base command for the survey CLI.
|
const appKey string = "app"
|
||||||
var RootCmd = &cobra.Command{
|
const long string = `Project Management Interface Survey
|
||||||
Use: "survey",
|
|
||||||
Long: `Project Management Interface Survey
|
|
||||||
|
|
||||||
Thank you for participating in our survey!
|
Thank you for participating in our survey!
|
||||||
|
|
||||||
@@ -15,7 +16,31 @@ We are gathering data on how users interact with different task management inter
|
|||||||
This survey will present you with a series of tasks to complete using various interfaces, including command-line, web-based, and terminal user interfaces.
|
This survey will present you with a series of tasks to complete using various interfaces, including command-line, web-based, and terminal user interfaces.
|
||||||
|
|
||||||
Please answer the questions honestly and to the best of your ability.
|
Please answer the questions honestly and to the best of your ability.
|
||||||
Your responses will be kept confidential and used solely for research purposes.`}
|
Your responses will be kept confidential and used solely for research purposes.`
|
||||||
|
|
||||||
|
var app *service.App
|
||||||
|
|
||||||
|
// RootCmd is the base command for the survey CLI.
|
||||||
|
var RootCmd = &cobra.Command{
|
||||||
|
Use: "survey",
|
||||||
|
Long: long,
|
||||||
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
if app != nil {
|
||||||
|
cmd.SetContext(context.WithValue(cmd.Context(), appKey, app))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetApp(application *service.App) {
|
||||||
|
app = application
|
||||||
|
}
|
||||||
|
|
||||||
|
func AppFromContext(ctx context.Context) *service.App {
|
||||||
|
if a, ok := ctx.Value(appKey).(*service.App); ok {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return app
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
RootCmd.CompletionOptions.DisableDefaultCmd = true
|
RootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
|
|||||||
Reference in New Issue
Block a user