Reduce startup time on Mac

This PR moves creating the API client into the returned predict
function. The creation of the client causes a lookup of all the system
certificates and doing that for each command on mac was extremely slow.
This commit is contained in:
Alex Dadgar
2017-08-28 11:29:27 -07:00
parent 4d97b302a0
commit 85a1899dfa
20 changed files with 21 additions and 23 deletions

View File

@@ -71,9 +71,9 @@ func (c *AllocStatusCommand) AutocompleteFlags() complete.Flags {
}
func (c *AllocStatusCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -51,8 +51,8 @@ func (c *DeploymentFailCommand) AutocompleteFlags() complete.Flags {
}
func (c *DeploymentFailCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -43,8 +43,8 @@ func (c *DeploymentPauseCommand) AutocompleteFlags() complete.Flags {
}
func (c *DeploymentPauseCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -61,8 +61,8 @@ func (c *DeploymentPromoteCommand) AutocompleteFlags() complete.Flags {
}
func (c *DeploymentPromoteCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -49,8 +49,8 @@ func (c *DeploymentResumeCommand) AutocompleteFlags() complete.Flags {
}
func (c *DeploymentResumeCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -52,8 +52,8 @@ func (c *DeploymentStatusCommand) AutocompleteFlags() complete.Flags {
}
func (c *DeploymentStatusCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -59,8 +59,8 @@ func (c *EvalStatusCommand) AutocompleteFlags() complete.Flags {
}
func (c *EvalStatusCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -94,9 +94,8 @@ func (c *FSCommand) AutocompleteFlags() complete.Flags {
}
func (f *FSCommand) AutocompleteArgs() complete.Predictor {
client, _ := f.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := f.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -51,8 +51,8 @@ func (c *InspectCommand) AutocompleteFlags() complete.Flags {
}
func (c *InspectCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -54,8 +54,8 @@ func (c *JobDeploymentsCommand) AutocompleteFlags() complete.Flags {
}
func (c *JobDeploymentsCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -66,8 +66,8 @@ func (c *JobDispatchCommand) AutocompleteFlags() complete.Flags {
}
func (c *JobDispatchCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -66,8 +66,8 @@ func (c *JobHistoryCommand) Autocompleteflags() complete.Flags {
}
func (c *JobHistoryCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -62,8 +62,8 @@ func (c *JobPromoteCommand) AutocompleteFlags() complete.Flags {
}
func (c *JobPromoteCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -49,8 +49,8 @@ func (c *JobRevertCommand) AutocompleteFlags() complete.Flags {
}
func (c *JobRevertCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -71,8 +71,8 @@ func (c *JobStatusCommand) AutocompleteFlags() complete.Flags {
}
func (c *JobStatusCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -75,9 +75,8 @@ func (c *LogsCommand) AutocompleteFlags() complete.Flags {
}
func (l *LogsCommand) AutocompleteArgs() complete.Predictor {
client, _ := l.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := l.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -56,8 +56,8 @@ func (c *NodeDrainCommand) AutocompleteFlags() complete.Flags {
}
func (c *NodeDrainCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -99,8 +99,8 @@ func (c *NodeStatusCommand) AutocompleteFlags() complete.Flags {
}
func (c *NodeStatusCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -37,8 +37,8 @@ func (c *StatusCommand) AutocompleteFlags() complete.Flags {
}
func (c *StatusCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}

View File

@@ -62,8 +62,8 @@ func (c *StopCommand) AutocompleteFlags() complete.Flags {
}
func (c *StopCommand) AutocompleteArgs() complete.Predictor {
client, _ := c.Meta.Client()
return complete.PredictFunc(func(a complete.Args) []string {
client, _ := c.Meta.Client()
if len(a.Completed) > 1 {
return nil
}