DEV Community

Pranav Karawale
Pranav Karawale

Posted on

My experience of writing a CLI in Go

How I ended up here?

So here I am, tinkering with React and Vite and Material UI, making a simple, productive app called Lookahead for the lay man and the hoodie(?) dev. Now, it turns out that, Google Keep doesn't have a CLI!! And here's what I think would be a great experience(and hopefully someone notices my work) to make a CLI interface for Lookahead. And so this is the high level overview of how I ended up here.

Why Go??

I was thinking of making the CLI in Node.js(feels like home for a webdev, right?). So, pkged or nexeed the file, I get the binary in build/. Hooray!! Just look to the right of the screen... file size : 130,769 KB. Yes, these numbers are as real as global warming is, I am not joking. How am I gonna distribute these?? Even .gz won't help(file size ~30MB). And those binaries are way too slow. I feel my heart pain while running the binary. And yeah, I also wanted to learn a new language after Web stuff and Python, and magically, the Gopher jumped out in the field!! And honestly, after 2 weeks, I am up and writing the CLI(though with not that much sense of convention and semanticity and stuff; will be dealt later). So I would like to give a little overview of what I have done, and will be doing.

Things I wish would have been done by somebody

And now I have a real, hard time with Firebase. No, not the API key stuff, but there is NO CLIENT LIBRARY!! Surely, there are official SDKs, but those are for server side(meh! my CLI ain't a server) so there is only one option, use the REST APIs!! And yeah, to be honest, now I feel pretty much comfortable with those APIs and stuff(REST APIs and not the fancy gRPC thingy)

Things that I have done

I just implemented some authentication logic which is displayed below:

From the user's side

User types look login -> User enters the email -> A sign-in link is sent to their mail -> They open it -> A message will come on their browser like "Yeah, open the CLI to continue" -> They open the CLI -> Signed in successfully!!!

From the CLI and server side

Request email link to be sent -> Wait for link to be opened -> After link is opened, get that oobCode parameter and temporarily store it -> Convert the oobCode into a Firebase ID token -> CLI gets the ID token, along with a refresh token, to renew the ID token -> BAM!! All well

Things yet to implement

  • Of course, the main purpose of the CLI, notes and to-dos... But I'll do it later next week, I have exams coming this week. This will need using the Firestore REST API (gRPC looks like overkill to me for this; I am not at all familiar with gRPC)
  • Refreshing the UX in the CLI

Ending here...

I will make some code posts, so be in the event loop to catch those. I hope you are having a nice day, reader!! Goodbye for now.

Top comments (2)

Collapse
 
pavelloz profile image
Paweł Kowalski

Surely, there are official SDKs, but those are for server side(meh! my CLI ain't a server)

Well, in bigger context, from firebase POV, it is. :)

Collapse
 
retronav profile image
Pranav Karawale

As for now, my binary size is roughly 8 MB, which is a significant improvement from the Node.js ones. But still major functionality is being worked out, so I guess the binary will grow to ~10MB