generated from cybozu-go/neco-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from cybozu-go/bash-completion
Implement completion
- Loading branch information
Showing
12 changed files
with
155 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func completeNamespaces(cmd *cobra.Command, args []string, toComplete string) (ret []string, directive cobra.ShellCompDirective) { | ||
ret = make([]string, 0) | ||
directive = cobra.ShellCompDirectiveNoFileComp | ||
|
||
clientset, _, err := createK8sClients() | ||
if err != nil { | ||
return | ||
} | ||
|
||
nss, err := clientset.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{}) | ||
if err != nil { | ||
return | ||
} | ||
|
||
for _, ns := range nss.Items { | ||
ret = append(ret, ns.Name) | ||
} | ||
return | ||
} | ||
|
||
func completePods(cmd *cobra.Command, args []string, toComplete string) (ret []string, directive cobra.ShellCompDirective) { | ||
ret = make([]string, 0) | ||
directive = cobra.ShellCompDirectiveNoFileComp | ||
|
||
clientset, _, err := createK8sClients() | ||
if err != nil { | ||
return | ||
} | ||
|
||
pods, err := listRelevantPods(context.Background(), clientset, rootOptions.namespace) | ||
if err != nil { | ||
return | ||
} | ||
|
||
for _, p := range pods { | ||
ret = append(ret, p.Name) | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
if ! grep boarded /root/.bashrc > /dev/null 2>&1; then | ||
echo '. /usr/share/bash-completion/bash_completion' >> /root/.bashrc | ||
echo 'export PATH=${PATH}:/tmp' >> /root/.bashrc | ||
echo '. <(npv completion bash)' >> /root/.bashrc | ||
echo '# boarded' >> /root/.bashrc | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.