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

Introduce interactive clc mode [API-689] #32

Merged
merged 14 commits into from Nov 29, 2021

Conversation

utku-caglayan
Copy link
Contributor

No description provided.

commands/root.go Outdated
if config := internal.Configuration; config != nil {
return fmt.Sprintf("hzc %s@%s> ", config.Cluster.Network.Addresses[0], config.Cluster.Name), true
}
return "hzc address@clusterName> ", true
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it probable that the configuration is nil? I think when this function is called, we should have already connected to the cluster, shouldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, fixed as suggested

- try to connect on start, fail fast if not successful
- provide longer versions of flags as suggestion
- add shell style parsing for interactive mode to work properly on inputs such as map put -n my-map -k "hello world" -v '{"json": 1}'
commands/root.go Outdated Show resolved Hide resolved
commands/root.go Outdated
cmd.PersistentFlags().StringVar(&token, "cloud-token", "", "your Hazelcast Cloud token.")
cmd.PersistentFlags().StringVarP(&internal.CfgFile, "config", "c", internal.DefautConfigPath(), fmt.Sprintf("config file (default is %s)", internal.DefautConfigPath()))
cmd.PersistentFlags().StringVarP(&internal.Address, "address", "a", "", "addresses of the instances in the cluster.")
cmd.PersistentFlags().StringVarP(&internal.Cluster, "cluster-name", "n", "", "name of the cluster that contains the instances.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we use -n for the map name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes correct, I removed the shorthand for this.

Comment on lines +30 to +32
// DynamicSuggestionsFunc will be executed if a command has CallbackAnnotation as an annotation. If it's included
// the value will be provided to the DynamicSuggestionsFunc function.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about not-breaking comment lines, and making each comment line its own sentence?

if co.RootCmd == nil {
panic("RootCmd is not set. Please set RootCmd")
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's try to use blank lines sparingly. Maybe we could use that space for a comment that explains the line below?

}

co.prepare()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's try to use blank lines sparingly. Maybe we could use that space for a comment that explains the code below?

commands/root.go Outdated
DisableCompletionCommand: true,
AddDefaultExitCommand: true,
GoPromptOptions: []prompt.Option{
prompt.OptionTitle("hazelcast commandline client"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this title displayed as the title of the terminal window? How about: "Hazelcast Commandline Client" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is, sure that makes sense. I would also prefer a shorter name since there are no guarantees that we will have sufficient space to display the whole title. What do you think of "Hazelcast Cli"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about "Hazelcast Client"?

commands/root.go Outdated
Comment on lines 120 to 122
RootCmd.Example = "> map put -k key -m myMap -v someValue\n" +
"> map get -k key -m myMap\n" +
"> cluster version"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of concatenating strings and adding line breaks, backticks (````) may be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch, thanks


func findSuggestions(co *CobraPrompt, d *prompt.Document) []prompt.Suggest {
command := co.RootCmd
args := strings.Fields(d.CurrentLine())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this cause a problem with args which have spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch, thanks. Fixed it with an external lib

command = found
}
var suggestions []prompt.Suggest
persistFlagValues, _ := command.Flags().GetBool(PersistFlagValuesFlag)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error is ignored here. Is that intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to add a workaround, because initiation of commands etc.. are a mess because of the global state. Changes are on 28bd268. I will keep this in mind for a refactor session if that is okay with you too.

Copy link
Collaborator

@yuce yuce left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!

@utku-caglayan utku-caglayan merged commit fe8e1ea into hazelcast:main Nov 29, 2021
@utku-caglayan utku-caglayan added this to the v1.0.0 milestone Jun 1, 2022
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.

None yet

2 participants