Пример #1
0
			Expect(opt.NoArgs()).To(Equal(true))
		})
		It("Should return false if arguments on the command line", func() {
			parser := args.Parser()
			parser.Opt("--power-level", args.IsInt(), args.Default("1"))

			opt, err := parser.ParseArgs(&[]string{"--power-level", "2"})
			Expect(err).To(BeNil())
			Expect(opt.Int("power-level")).To(Equal(2))
			Expect(opt.NoArgs()).To(Equal(false))
		})
	})

	Describe("parser.GenerateOptHelp()", func() {
		It("Should generate help messages given a set of rules", func() {
			parser := args.Parser(args.WrapLen(80))
			parser.Opt("--power-level", args.Alias("-p"), args.Help("Specify our power level"))
			parser.Opt("--cat-level", args.Alias("-c"), args.Help(`Lorem ipsum dolor sit amet, consectetur
			mollit anim id est laborum.`))
			msg := parser.GenerateOptHelp()
			Expect(msg).To(Equal("  -p, --power-level   Specify our power level " +
				"\n  -c, --cat-level     Lorem ipsum dolor sit amet, consecteturmollit anim id est" +
				"\n                      laborum. \n"))
		})
	})

	/*Describe("parser.GenerateHelp()", func() {
			It("Should generate help messages given a set of rules", func() {
				parser := args.Parser(args.Name("dragon-ball"), args.WrapLen(80))
				parser.Opt("--power-level", args.Alias("-p"), args.Help("Specify our power level"))
				parser.Opt("--cat-level", args.Alias("-c"), args.Help(`Lorem ipsum dolor sit amet, consectetur
Пример #2
0
		})
	})
	Describe("ArgParser.AddRule()", func() {
		cmdLine := []string{"--power-level", "--power-level"}
		It("Should add new rules", func() {
			parser := args.NewParser()
			rule := args.NewRuleModifier(parser).Count().Help("My help message")
			parser.AddRule("--power-level", rule)
			opt, err := parser.ParseArgs(&cmdLine)
			Expect(err).To(BeNil())
			Expect(opt.Int("power-level")).To(Equal(2))
		})
	})
	Describe("ArgParser.GenerateOptHelp()", func() {
		It("Should generate help messages given a set of rules", func() {
			parser := args.NewParser(args.WrapLen(80))
			parser.AddOption("--power-level").Alias("-p").Help("Specify our power level")
			parser.AddOption("--cat-level").
				Alias("-c").
				Help(`Lorem ipsum dolor sit amet, consectetur
			mollit anim id est laborum.`)
			msg := parser.GenerateHelpSection(args.IsOption)
			Expect(msg).To(Equal("  -p, --power-level   Specify our power level" +
				"\n  -c, --cat-level     Lorem ipsum dolor sit amet, consecteturmollit anim id est" +
				"\n                      laborum.\n"))
		})
	})
	Describe("ArgParser.GenerateHelp()", func() {
		It("Should generate help messages given a set of rules", func() {
			parser := args.NewParser(args.EnvPrefix("APP_"), args.Desc("Small Description"),
				args.Name("dragon-ball"), args.WrapLen(80))