Giter Site home page Giter Site logo

Comments (4)

devfacet avatar devfacet commented on August 26, 2024 1

Yes, it seems a bug. Give me a few days, I'll fix it asap.

P.S. Thanks for taking your time and reporting issues. I appreciate it...

from gocmd.

devfacet avatar devfacet commented on August 26, 2024

See os.Args;

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/devfacet/gocmd"
)

func main() {

	fmt.Printf("args: %#v\n", os.Args)

	flags := struct {
		Command struct{} `command:"command"`
		Flag    string   `short:"f" long:"flag" required:"true"`
	}{}

	_, err := gocmd.New(gocmd.Options{
		Flags:    &flags,
		AnyError: true,
	})

	if err != nil {
		log.Fatal(err)
	}
}
$ go run main.go -f command
args: []string{"/var/folders/.../exe/main", "-f", "command"}
2018/03/18 11:59:12 argument -f needs a nonempty value
exit status 1

$ go run main.go -f "command"
args: []string{"/var/folders/.../exe/main", "-f", "command"}
2018/03/18 11:59:17 argument -f needs a nonempty value
exit status 1

$ go run main.go -f 'command'
args: []string{"/var/folders/.../exe/main", "-f", "command"}
2018/03/18 12:07:14 argument -f needs a nonempty value
exit status 1

$ go run main.go -f "\"command\""
args: []string{"/var/folders/.../exe/main", "-f", "\"command\""}

As you can see " and ' are stripped from os.Args values. So gocmd's behavior seems correct ("command" and 'command' are interpreted as command). I need to check other libraries and see whether this is a correct behavior or not. If it's not then I need to figure out how to get raw command line arguments in Go. It may take sometime...

from gocmd.

sirmar avatar sirmar commented on August 26, 2024

I'm not sure I follow you�. Surely the Os args value should strip the citations, that's not the issue. However it should not be interpreted as command as the order of arguments is different. After a flag that takes a string, it should be parsed as that string (as for all other strings), not as a subcommand.

This would mean that it would be impossible to run git commit -m "log" just because git log is a command.

from gocmd.

devfacet avatar devfacet commented on August 26, 2024

In this case how can I determine whether the command line argument is a "command" or an "argument value" since os.Args values are stripped? See;

# -f is an argument flag and bar is a command flag
$ go run main.go -f bar
args: []string{"/var/folders/.../exe/main", "-f", "bar"}

# -f is an argument flag and bar is an argument value
$ go run main.go -f "bar"
args: []string{"/var/folders/.../exe/main", "-f", "bar"}

In both cases os.Args returns bar and I don't know how to check whether it is just bar (command) or "bar" argument value.

from gocmd.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.