Help with Command line arguments

Hey Everyone,

I’m super new to Golang and programming in general, so I apologize for the noob question.

I’m writing a command-line tool that checks device information against an API and generates some configurations.

When running the tool, I would like to include 3 arguments, have the arguments checked to ensure they’re valid and then run the code I’ve written.

Any tips would be greatly appreciated.

You can access command line arguments in os.Args, and get the number of arguments with len(). Here is a simple example:

package main

import (

func main() {
        for i := 1; i < len(os.Args); i++ {

very helpful, thank you!

If you want to use flags on the commandline like

mycommnd -v -t 33 -path ./folder

Can you use the flags package in the standard library

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.