Published on August 13, 2020 (over 3 years ago)

Hey look, a Mux CLI

Matthew McClure
By Matthew McClure2 min readEngineering

At the end of last year I wrote a small CLI to make my life a little easier. I kept finding myself doing the same manual things over and over, so like any lazy procrastinating good dev I spent a few hours writing code to knock off a minute or two each time I need to do one of these tasks.

I should stress, this tool should be considered beta. I've been using it myself for a few months along with a few other folks internally (they claim), as well as the occasional friendly customer. The last friendly customer seemed offended that this wasn't more accessible, so we decided to go ahead and make it public.

LinkGetting Started

First you need to install the CLI however you normally install global packages. I personally use Volta so I'm biased, but you can pick your poison.

$ volta install @mux/cli $ npm install -g @mux/cli $ yarn global add @mux/cli

From there you'll need to initialize the CLI so it has the right credentials set up. If you haven't already, create a Mux Access Token in your dashboard and give it the appropriate access (you probably want read/write access for Video at least or it's not going to be terribly useful). Save the newly created access token locally when asked. For this example, we'll save it to ~/Downloads/MuxToken.env.

Now use that .env file to initialize the CLI!

$ mux init ~/Downloads/MuxToken.env Loaded your Mux .env file! Using token with id: 5a12be37-73a9-4283-a070-02f5e1f9adb5? Do you want to go ahead and set up a Signing Key? This is used to create tokens for signed playback policies. Yes Configuration written to: /home/janedoe/.config/@mux/cli/config.json

You can also call init without specifying an environment file and the CLI will prompt you for your token ID and secret. The CLI will also ask if you want to go ahead and set up a signing key. This is optional, but you might want to do it if you want to use the signed playback policy tools.

From here, you can go wild! You can upload a handful of files from a directory if you'd like:

$ mux assets:upload -f .mp4 ~/Videos ? We found a few files! Do all of these look good? (Press <space> to select, <a> to toggle all, <i> to invert selection) ❯◉ ColorSpaces.mp4 ◉ MuxLonger.mp4 ◉ mux-video-intro.mp4 ◉ mux-video-live-background.mp4 ◉ roll.mp4 ◉ sfvideo_talk_2020_06.mp4 (Move up and down to reveal more choices)

LinkWhat's next?

We've got big plans for the CLI long term! Standalone binaries, easier initialization, and a laundry list of features are just a few of the things we've got planned right now. We'd love to hear how you'd like to use it, though, so feel free to let us know via an issue on the Github repo!

Happy hacking!

Written By

Matthew McClure

Matthew McClure – Co-Founder and VP of Developer Experience

Creator of Demuxed and wrangler of meetup speakers. Used to write a lot of React and Elixir code. Still do sometimes, but used to, too.

Leave your wallet where it is

No credit card required to get started.