-
Notifications
You must be signed in to change notification settings - Fork 29
refactor: remove logger from create command #366
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,6 @@ import ( | |
| "time" | ||
|
|
||
| "github.com/slackapi/slack-cli/internal/iostreams" | ||
| "github.com/slackapi/slack-cli/internal/logger" | ||
| "github.com/slackapi/slack-cli/internal/pkg/create" | ||
| "github.com/slackapi/slack-cli/internal/shared" | ||
| "github.com/slackapi/slack-cli/internal/slackerror" | ||
|
|
@@ -43,11 +42,6 @@ var createSubdirFlag string | |
| // TODO - Find best practice, such as using an Interface and Struct to create a client | ||
| var CreateFunc = create.Create | ||
|
|
||
| var appCreateSpinner *style.Spinner | ||
|
|
||
| const copyTemplate = "Copying" | ||
| const cloneTemplate = "Cloning" | ||
|
|
||
|
Comment on lines
-46
to
-50
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Removing because the spinner was never started in the current code. |
||
| // promptObject describes the Github app template | ||
| type promptObject struct { | ||
| Title string // "Reverse string" | ||
|
|
@@ -93,9 +87,6 @@ name your app 'agent' (not create an AI Agent), use the --name flag instead.`, | |
| func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
|
|
||
| // Set up event logger | ||
| log := newCreateLogger(clients, cmd) | ||
|
|
||
| // Get optional app name passed as an arg and check for category shortcuts | ||
| appNameArg := "" | ||
| categoryShortcut := "" | ||
|
|
@@ -166,9 +157,6 @@ func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command, args [] | |
| } | ||
| } | ||
|
|
||
| // Set up spinners | ||
| appCreateSpinner = style.NewSpinner(cmd.OutOrStdout()) | ||
|
|
||
| createArgs := create.CreateArgs{ | ||
| AppName: appNameArg, | ||
| Template: template, | ||
|
|
@@ -177,88 +165,15 @@ func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command, args [] | |
| } | ||
| clients.EventTracker.SetAppTemplate(template.GetTemplatePath()) | ||
|
|
||
| appDirPath, err := CreateFunc(ctx, clients, log, createArgs) | ||
| appDirPath, err := CreateFunc(ctx, clients, createArgs) | ||
| if err != nil { | ||
| printAppCreateError(clients, cmd, err) | ||
| return err | ||
| } | ||
|
|
||
| printCreateSuccess(ctx, clients, appDirPath) | ||
| return nil | ||
| } | ||
|
|
||
| /* | ||
| App creation is setting up local project directory | ||
| Events: on_app_create_completion | ||
| */ | ||
|
|
||
| // newCreateLogger creates a logger instance to receive event notifications | ||
| func newCreateLogger(clients *shared.ClientFactory, cmd *cobra.Command) *logger.Logger { | ||
| return logger.New( | ||
| // OnEvent | ||
| func(event *logger.LogEvent) { | ||
| switch event.Name { | ||
| case "on_app_create_template_default": | ||
| printAppCreateDefaultemplate(cmd, event) | ||
| case "on_app_create_template_custom": | ||
| printAppCreateCustomTemplate(cmd, event) | ||
|
Comment on lines
-200
to
-203
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: Neither of these events were ever called. This is why the spinner was never started. |
||
| case "on_app_create_completion": | ||
| printProjectCreateCompletion(clients, cmd, event) | ||
|
Comment on lines
-204
to
-205
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: This event was correctly called, but the spinner was never started so any calls to stop it are ignored. |
||
| default: | ||
| // Ignore the event | ||
| } | ||
| }, | ||
| ) | ||
| } | ||
|
|
||
| /* | ||
| App creation (not Create command) is cloning the template and creating the project directory | ||
| Events: on_app_create_template_custom, on_app_create_completion | ||
| */ | ||
|
|
||
| func printAppCreateDefaultemplate(cmd *cobra.Command, event *logger.LogEvent) { | ||
| startAppCreateSpinner(copyTemplate) | ||
| } | ||
|
|
||
| // Print template URL if using custom app template | ||
| func printAppCreateCustomTemplate(cmd *cobra.Command, event *logger.LogEvent) { | ||
| var verb string | ||
| templatePath := event.DataToString("templatePath") | ||
| isGit := event.DataToBool("isGit") | ||
| gitBranch := event.DataToString("gitBranch") | ||
|
|
||
| if isGit { | ||
| verb = cloneTemplate | ||
| } else { | ||
| verb = copyTemplate | ||
| } | ||
| templateText := fmt.Sprintf( | ||
| "%s template from %s", | ||
| verb, | ||
| templatePath, | ||
| ) | ||
|
|
||
| if gitBranch != "" { | ||
| templateText = fmt.Sprintf("%s (branch: %s)", templateText, gitBranch) | ||
| } | ||
|
|
||
| cmd.Print(style.Secondary(templateText), "\n\n") | ||
|
|
||
| startAppCreateSpinner(verb) | ||
| } | ||
|
|
||
| func startAppCreateSpinner(verb string) { | ||
| appCreateSpinner.Update(verb+" app template", "").Start() | ||
| } | ||
|
|
||
| // Display message and added files at completion of app creation | ||
| func printProjectCreateCompletion(clients *shared.ClientFactory, cmd *cobra.Command, event *logger.LogEvent) { | ||
| createCompletionText := style.Sectionf(style.TextSection{ | ||
| Emoji: "gear", | ||
| Text: "Created project directory", | ||
| }) | ||
| appCreateSpinner.Update(createCompletionText, "").Stop() | ||
| } | ||
|
|
||
| // printCreateSuccess outputs an informative message after creating a new app | ||
| func printCreateSuccess(ctx context.Context, clients *shared.ClientFactory, appPath string) { | ||
| // Check if this is a Deno project to conditionally enable some features | ||
|
|
@@ -318,15 +233,3 @@ func generateRandomAppName() string { | |
| var randomName = fmt.Sprintf("%s-%s-%d", create.Adjectives[firstRandomNum], create.Animals[secondRandomNum], rand.Intn(1000)) | ||
| return randomName | ||
| } | ||
|
|
||
| // printAppCreateError stops the creation spinners and displays the returned error message | ||
| func printAppCreateError(clients *shared.ClientFactory, cmd *cobra.Command, err error) { | ||
| ctx := cmd.Context() | ||
| switch { | ||
| case appCreateSpinner.Active(): | ||
| errorText := fmt.Sprintf("Error creating project directory: %s", err) | ||
| appCreateSpinner.Update(errorText, "warning").Stop() | ||
| default: | ||
| } | ||
| clients.IO.PrintTrace(ctx, slacktrace.CreateError) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: Just adding this to scratch an itch where Claude fails to format files correctly.