kube-aliases
kube-aliases copied to clipboard
Generate aliases
Generate aliases!
I'd like to modify the bin/ stuff before we merge. Some of it could be reduced to aliases. The others might work better using go and then some aliases. But if you wanna merge sooner that's fine by me. 
Also. We should tag the current version before moving on. Just in case people wanna keep using previous version.
I'm in no rush to merge. I'd love to get this polished before that. I'll actually work off a branch and then merge into this branch. I only created a PR because it's the easiest way for me to view the diff 😂 , and we can comment on the code here.
Also. We should tag the current version before moving on. Just in case people wanna keep using previous version.
Good idea 👍
I created a PR to rebase this branch on top of master: https://github.com/Dbz/kube-aliases/pull/21
It definitely needs some 👀
So with generation, I currently give everything all the base commands. But I think it may be better to have each resource have a list of commands that it wants. This way we whitelist the cmds we want for each resource.
Actually, I think this might simplify it.
Hey, I merged and changed a few things.
Offhand, the only thing was an underscore in the tests seems unconventional. Also, when reading in an aliases I dont think order is guaranteed so the test fails sometimes. Im going to adjust it a little bit but need to go for the day and am commiting.
Also, wanna move test cases yaml files into generate/tests just so we can test specific things there.
Ive never used require before. Will have to check it out.
Earlier commit I moved types into their own thing. I believe its more conventional.
What do you think about removing bin/generate-kube-aliases
from git? Seems like something to add to the .gitignore
. I didn't want to do that without asking you first
What do you think about removing
bin/generate-kube-aliases
from git? Seems like something to add to the.gitignore
. I didn't want to do that without asking you first
Yea, I think so. Im thinking we generate a default file for users to source and only if they want they can use the generate tool. Figure we can make them into releases. Probably should have it ignore bin completely.
This last commit allows for additional aliases. Essentially we can generate everything to a single file.
Im happy to revert back if this isnt the direction youd like to go.
Guess let me know what you think from here.
Couple of thoughts. I have.
- Probably can change cmds to a list like I had additional. I dont think it needs to be a map.
- More tests - make sure things fail nicely
- Build a release
- Redo readme - most users will probably just want to source the generated file
OK, here is the PR to remove the leaky abstraction. I did a little bit of extra refactoring to combine Generate
and GenerateAdditional
: https://github.com/Dbz/kube-aliases/pull/26
Well, I think this is looking great.
I like all of your bullets. I would add we should make the user provided aliases go into a separate file so we're not overriding it on update.
Hmmm... that seems to have broken stuff. Tests are passing, but if you actually use the tool its broken. I have fixed that (need to initialize the map) but now the tests are always passing. So gotta figure out what that is all about.
It seems to be true on commit before yours so I shall see.
It is the TestMain function. Itll be fixed next commit.
So I realize, in order to allow folks to generate their own stuff, we do need to include a binary in git :( . I usually dislike that, so maybe let's generate one per release?
Possible solution:
Don't provide it in the repository. And pretty much have one file that they can source. It'll have good defaults.
Have a binary that we keep with the release. That's where it belongs anyway. If users want to generate them they can download that release.
I imagine most people just wanna source a file and be done. But just in case, think we should have all the commands be copy and paste.
I made some modifications for my personal use to create aliases for powershell. I don't know go, so I am vary of opening a PR, but the basic idea is as follows
diff --git a/generate/pkg/generate/generate.go b/generate/pkg/generate/generate.go
index 069a456..e083c42 100644
--- a/generate/pkg/generate/generate.go
+++ b/generate/pkg/generate/generate.go
@@ -104,7 +104,9 @@ func GenerateAlias(w io.Writer, aliases *types.AliasCMDs) error {
lastResource = alias.Resource
}
- fmt.Fprintf(w, "alias %v=\"%v\"\n", aliasName, aliasCommand)
+ ps1prefix := "ps1_"
+ fmt.Fprintf(w, "function %v%v {%v $args}\n", ps1prefix, aliasName, aliasCommand)
+ fmt.Fprintf(w, "New-Alias -Name %v -Value %v%v\n", aliasName, ps1prefix, aliasName)
}
var comment string
@@ -121,7 +123,9 @@ func GenerateAlias(w io.Writer, aliases *types.AliasCMDs) error {
comment = alias.Comment
}
- fmt.Fprintf(w, "alias %v=\"%v\"\n", alias.Short, alias.CMD)
+ ps1prefix := "ps1_"
+ fmt.Fprintf(w, "function %v%v {%v $args}\n", ps1prefix, alias.Short, alias.CMD)
+ fmt.Fprintf(w, "New-Alias -Name %v -Value %v%v\n", alias.Short, ps1prefix, alias.Short)
}
return nil
}
It would be very nice if something like this could be accommodated. I will work on fixing it...
Hi @anupamsr . I'm happy to accommodate :)
What should do is work together on a PR to create a new generated file specifically for powershell users. Should should be able to do that with a minimal amount of code.
@anupamsr -- started the support. Thank ya. 6199509f06cede43c5d2d732e81a3d53b28bd271
Hi. Is there a plan to add aliases for kubectl context? I mean, something like
--- a/aliases.yaml
+++ b/aliases.yaml
@@ -164,4 +164,13 @@ additional:
- short: keit
cmd: "kubectl exec -it"
comment: "Exec alias."
+ - short: kk
+ cmd: "kubectl config"
+ comment: "Modify kubeconfig files."
+ - short: kkc
+ cmd: "kubectl config get-contexts"
+ comment: "Describe one or many contexts."
+ - short: kku
+ cmd: "kubectl config use-context"
+ comment: "Set the current-context in a kubeconfig file."
I am just about learning kubernetes devops so it if you think there is a better way, I would really appriciate knowing that.
Sure, if you want you can open a pull request and Ill merge it in. If not, Ill add it.
Yes, if you're going to open a PR which would be awesome, please base it off of this branch!
Done. Please have a look: https://github.com/Dbz/kube-aliases/pull/34