Posts tagged with "cli"
There's a decent chance that you, like me, ended up with Visual Studio Code incorrectly configured as Git's core editor. I'm talking about Windows here.
Take a look at your .gitconfig file and see what you have configured. You will likely find that in c:\users\<username>.
Under the [core] section, look for the editor key. What do you have for a value?
If your Visual Studio Code path ends with code.cmd, then it's not correct. It should end with code.exe. And it should have a -w flag. The -w flag tells the launching context to block until the process is terminated. That means that if you run a Git command from the command line that launches Code as a text editor, the command line should be blocked until you're done editing that file and shut down Code.
Let's say, for instance, that you have committed some files and then realize that you forgot one. You could commit it as a new commit, but it makes more sense to tack the change on to the last commit (assuming you haven't pushed your commit up to a shared repo yet!).
To do this, you simply run
git commit --amend at the command line. This amends your staged files to the last commit. It also launches your default text editor so you can determine if you want to keep the same commit message you elected previously or overwrite it.
This should open your text editor, wait for you to make and save your changes and then shut down your editor before releasing control of the command line and continuing on.
You can simply edit your .gitconfig file to add this configuration, but it's easier to run this…
git config --global core.editor "'C:\Program Files (x86)\Microsoft VS Code\code.exe' -w"
…from your command line.
At the time of this writing, there are two Azure portals you can use.
To get to the main, full-featured, current Azure portal, you browse to manage.windowsazure.com in any modern browser, and it looks like this…
The new portal is already available for you to play with and get familiar with, and it's a good thing too since it takes quite a bit of getting used to. Once you grok it, though, I'm pretty sure you'll like it better. You get to the new portal by browsing to portal.azure.com. Here's what it looks like…
Both of these are works of modern, web art and very functional in my opinion. I love the current portal, and now that I'm accustomed to it, I love the new portal as well.
But I would like to get to the place where I have little to no need for the portals. I would like to instead to be utterly dependent on the command line.
I started some time back on the PowerShell command interface for Azure and it's very well made. I had a hard time getting to it though. I suppose it was the long commands - the PowerShell syntax. Although it's quite descriptive and offers good tab completion and documentation, I still found it a chore and kept at my work in the portal.
I had a glance some time ago at the node tooling for Azure as well, but didn't really give it a fair shake. Now I'm shaking it like crazy and really excited. Check out some of these things you can do…
The following will generate a list of Azure VM images and allows me to pipe to a regular expression to pull out just the stable (LTS) Ubuntu images of a certain version (14.04.1). It's also possible to add a
--jsonproperty to the request and get this data back in JSON format.
Once I've chosen the image I want to start with, I simple call the following to create a new VM in the West US region. I add the
-e parameter to add ssh capability so I can ssh into the machine when it's finished.
Now let's fetch a list of my VM's and see the new mynewubuntumachine in there…
By the way, if you're like me and like staying in the command line interface, try installing Cygwin. It runs great in PowerShell and allows me immediately after creating this VM to ssh into it like so…
I'd rather that machine not start charging me for compute, so let's shut it down and make it free (except for a little bit of storage… pennies)…
What else can we do with the azure-cli? Oh, man. Glad you asked. Let's create a quick Azure Mobile Service, add a table, and then use some PowerShell candy to start writing and reading records.
First, we create the service like the following where gg4p4pzmfi is simply the name of my particular SQL Server. I already have it, so I may as well use that instead of creating a new one. My service is actually going to be called "cfms".
Then we create a table. Let's just punt and call it widgets. In order to show interactions with the table via simple HTTP commands, I'm going to open up the insert and read permissions so I don't have to create authentication headers in my HTTP calls…
And there we have a service with a table ready for us. Now, in case you've never noticed, PowerShell natively allows us to use
curlto do web requests, but curl is not really installed. Instead it's a simple alias to the Invoke-WebRequest method in PowerShell. I chose to write the following functions into my PowerShell profile so it's always available to me…
So now we can write a record into our new widgets table like so…
Do notice that the response we got back from this post included the actual inserted object complete with the GUID that Azure Mobile Services tacked on to it. In case you're not already familiar with Mobile Services, you should also take note that we didn't schematize this table when we created it. Instead, we simply created an object with a name property and let Mobile Services handle that for us.
Now, a get from the same table should show us our widget 1 record, and in fact it does…
I love how simple and elegant a solution this is.
There's obviously a whole lot more we can do with azure-cli that I won't take the time to detail. But there's one more thing you should see - the inline help. For any command, simply tack on -h and you will get good information about the various possible parameters you can use. It's contextual too. If you type
azure -h, you'll see all of the high level options for the azure-cli tool, whereas if you type
azure vm -h, you'll see specific commands for working with VM's.
The azure -h is great for giving you an overview of what the tool will do.
I hope you have as much fun with this as I have already.
To get started, visit this page to see instructions on installing the tooling.