Skip to content

feat(kafka): add interactive prompt for kafka use#510

Merged
rkpattnaik780 merged 4 commits intomainfrom
kafka_use_prompt
Mar 31, 2021
Merged

feat(kafka): add interactive prompt for kafka use#510
rkpattnaik780 merged 4 commits intomainfrom
kafka_use_prompt

Conversation

@rkpattnaik780
Copy link
Contributor

Description

rhoas kafka use should prompt a list of available kafka instances.

Screenshot from 2021-03-29 16-34-37

fixes #496

Verification Steps

  1. Run go run ./cmd/rhoas kafka use
  2. It should prompt a list of Kafka instances to select.
  3. Navigate using arrow keys and press enter to select an instance.
  4. The terminal should output
Kafka instance "<name of selected kafka instance>" has been set as the current instance.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

- [ ] Documentation added for the feature

  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer

@rkpattnaik780 rkpattnaik780 changed the title feat: add interactive prompt for kafka use feat(kafka): add interactive prompt for kafka use Mar 29, 2021
Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change I think we should definitely make is increasing the limit on the list Kafkas, the rest are nits.

func runUse(opts *Options) error {

if opts.interactive {
// run the create command interactively
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// run the create command interactively
// run the use command interactively

return err
}

opts.name = *selectedKafka.Name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: I like to use the getter methods when they are available, it looks cleaner than pointers and removes the unlikely even of a nil pointer error.

Suggested change
opts.name = *selectedKafka.Name
opts.name = selectedKafka.GetName()

@@ -17,11 +18,11 @@ func InteractiveSelect(connection connection.Connection, logger logging.Logger)
response, _, apiErr := api.Kafka().ListKafkas(context.Background()).Execute()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should set the limit to something higher than the default limit, which is 100 I believe. In the event that a user is in an organisation which has > 100 instances, not all will show up to select from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much should we set it exactly?

one = 'unable to list Kafka instances'

[kafka.common.input.instanceName.message]
description = 'title for the Partitions input'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong description (but you can remove the description as the title is already self describing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact in most cases, you need not add the description, unless it is unclear from the message itself what its purpose is.

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One change needed.

Comment on lines 54 to 58
if len(args) > 0 {
opts.name = args[0]
} else if opts.id == "" {
return errors.New(localizer.MustLocalizeFromID("kafka.common.error.idFlagRequired"))
opts.interactive = true
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an error thrown when TTY is unavailable also.

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I have verified this in a non-TTY simulation by running the following:

❯ (setsid ./rhoas kafka use) </dev/null |& cat

Error: --id or name required when not running interactively

}

if response.Size == 0 {
logger.Info("No Kafka instances")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for localizing things as you go along :)

@rkpattnaik780 rkpattnaik780 merged commit d140df6 into main Mar 31, 2021
@rkpattnaik780 rkpattnaik780 deleted the kafka_use_prompt branch March 31, 2021 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rhoas kafka use should prompt with a list of available kafka instances to use

2 participants