// cmdRoutine runs a language parser on a project.
435370
func cmdRoutine(parsersPath, parserName, projectPath string, c chan *bytes.Buffer) {
	outBuf := new(bytes.Buffer)
	errBuf := new(bytes.Buffer)

	parserBin := filepath.Join(parsersPath, parserName, "parser")

	cmd := exec.Command(parserBin, projectPath)
	cmd.Stdout = outBuf
	cmd.Stderr = errBuf

	log.Debug("command: ", strings.Join(cmd.Args, " "))

	if err := cmd.Run(); err != nil {
		log.Debug("debug:", err)
		log.Fatal(fmt.Sprintf("failed to parse with the %s parser", parserName))
	}

	if errBuf.Len() > 0 {
		log.Info(fmt.Sprintf("parser %s errors:", parserName))
		log.Fail(errBuf.String())
	}

	if outBuf.Len() == 0 {
		log.Fatal(fmt.Sprintf("the %s parser did not produce any output", parserName))
	}

	c <- outBuf
}
1213575
func (u URL) Cmp(url URL) int {
	if u.Scheme == url.Scheme {
		return strings.Compare(u.Path, url.Path)
	}
	return strings.Compare(u.Scheme, url.Scheme)
}
861076
func NewCmdExplain(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
	o := NewExplainOptions(parent, streams)

	cmd := &cobra.Command{
		Use:                   "explain RESOURCE",
		DisableFlagsInUseLine: true,
		Short:                 i18n.T("Documentation of resources"),
		Long:                  explainLong + "\n\n" + cmdutil.SuggestAPIResources(parent),
		Example:               explainExamples,
		Run: func(cmd *cobra.Command, args []string) {
			cmdutil.CheckErr(o.Complete(f, cmd))
			cmdutil.CheckErr(o.Validate(args))
			cmdutil.CheckErr(o.Run(args))
		},
	}
	cmd.Flags().BoolVar(&o.Recursive, "recursive", o.Recursive, "Print the fields of fields (Currently only 1 level deep)")
	cmd.Flags().StringVar(&o.APIVersion, "api-version", o.APIVersion, "Get different explanations for particular API version")
	return cmd
}
1301620
func (c *CmdClause) Command(name, help string) *CmdClause {
	cmd := c.addCommand(name, help)
	cmd.parent = c
	return cmd
}
347889
func cmdInstalled(params Parameters) *subcommands.Command {
	return &subcommands.Command{
		Advanced:  true,
		UsageLine: "installed [options]",
		ShortDesc: "lists packages installed in the site root",
		LongDesc:  "Lists packages installed in the site root.",
		CommandRun: func() subcommands.CommandRun {
			c := &installedRun{defaultServiceURL: params.ServiceURL}
			c.registerBaseFlags()
			c.siteRootOptions.registerFlags(&c.Flags)
			return c
		},
	}
}
123886
func Parse() string {
	selected := MustParse(CommandLine.Parse(os.Args[1:]))
	if selected == "" && CommandLine.cmdGroup.have() {
		Usage()
		CommandLine.terminate(0)
	}
	return selected
}
603544
func Parse(cmds []string) ([]*api.GenericResource, error) {
	tokens := make(map[string][]string)

	for _, term := range cmds {
		kva := strings.Split(term, "=")
		if len(kva) != 2 {
			return nil, newParseError("incorrect term %s, missing"+
				" '=' or malformed expression", term)
		}

		key := strings.TrimSpace(kva[0])
		val := strings.TrimSpace(kva[1])

		tokens[key] = append(tokens[key], val)
	}

	var rs []*api.GenericResource
	for k, v := range tokens {
		if u, ok := isDiscreteResource(v); ok {
			if u < 0 {
				return nil, newParseError("cannot ask for"+
					" negative resource %s", k)
			}

			rs = append(rs, NewDiscrete(k, u))
			continue
		}

		if allNamedResources(v) {
			rs = append(rs, NewSet(k, v...)...)
			continue
		}

		return nil, newParseError("mixed discrete and named resources"+
			" in expression '%s=%s'", k, v)
	}

	return rs, nil
}
933187
func (c *ServicedCli) cmdServiceList(ctx *cli.Context) {
	if len(ctx.Args()) > 0 {
		svc, _, err := c.searchForService(ctx.Args().First(), ctx.Bool("no-prefix-match"))
		if err != nil {
			fmt.Fprintln(os.Stderr, err)
			c.exit(1)
			return
		}

		if service, err := c.driver.GetService(svc.ID); err != nil {
			fmt.Fprintln(os.Stderr, err)
			c.exit(1)
		} else if service == nil {
			fmt.Fprintln(os.Stderr, "service not found")
			c.exit(1)
			return
		} else {
			if ctx.String("format") == "" {
				if jsonService, err := json.MarshalIndent(service, " ", "  "); err != nil {
					fmt.Fprintf(os.Stderr, "failed to marshal service definition: %s\n", err)
					c.exit(1)
				} else {
					fmt.Println(string(jsonService))
				}
			} else {
				tpl := ctx.String("format")
				log := log.WithFields(logrus.Fields{
					"format": tpl,
				})
				if tmpl, err := template.New("template").Parse(tpl); err != nil {
					log.WithError(err).Error("Unable to parse format template")
					c.exit(1)
				} else if err := tmpl.Execute(os.Stdout, service); err != nil {
					log.WithError(err).Error("Unable to execute template")
					c.exit(1)
				}
			}
		}
		return
	}

	services, err := c.driver.GetAllServiceDetails()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		c.exit(1)
		return
	} else if services == nil || len(services) == 0 {
		fmt.Fprintln(os.Stderr, "no services found")
		c.exit(1)
		return
	}

	if ctx.Bool("verbose") {
		if jsonService, err := json.MarshalIndent(services, " ", "  "); err != nil {
			fmt.Fprintf(os.Stderr, "failed to marshal service definitions: %s\n", err)
			c.exit(1)
		} else {
			fmt.Println(string(jsonService))
		}
	} else if ctx.String("format") == "" {

		cmdSetTreeCharset(ctx, c.config)

		servicemap := api.NewServiceMap(services)
		t := NewTable(ctx.String("show-fields"))

		var addRows func(string)
		addRows = func(root string) {
			rowids := servicemap.Tree()[root]
			if len(rowids) > 0 {
				sort.Strings(rowids)
				t.IndentRow()
				defer t.DedentRow()
				for _, rowid := range rowids {
					row := servicemap.Get(rowid)
					// truncate the image id
					var imageID string
					if strings.TrimSpace(row.ImageID) != "" {
						id := strings.SplitN(row.ImageID, "/", 3)
						id[0] = "..."
						id[1] = id[1][:7] + "..."
						imageID = strings.Join(id, "/")
					}
					t.AddRow(map[string]interface{}{
						"Name":      row.Name,
						"ServiceID": row.ID,
						"Inst":      row.Instances,
						"ImageID":   imageID,
						"Pool":      row.PoolID,
						"DState":    row.DesiredState,
						"Launch":    row.Launch,
						"DepID":     row.DeploymentID,
					})
					addRows(row.ID)
				}
			}
		}
		addRows("")
		t.Padding = 6
		t.Print()
	} else {
		tpl := ctx.String("format")
		log := log.WithFields(logrus.Fields{
			"format": tpl,
		})
		tmpl, err := template.New("template").Parse(tpl)
		if err != nil {
			log.WithError(err).Error("Unable to parse template")
			c.exit(1)
		}
		for _, service := range services {
			if err := tmpl.Execute(os.Stdout, service); err != nil {
				log.WithError(err).Error("Unable to execute template")
				c.exit(1)
			}
		}
	}
	return
}
1108120
func (c *Cmd) CmdRun() error {

	var err error

	err = c.CmdStart()
	if err != nil {
		return err
	}

	c.CmdWait()
	return nil
}
723262
func DDLParse(sql string) (plan *DDLPlan) {
	statement, err := sqlparser.Parse(sql)
	if err != nil {
		return &DDLPlan{Action: ""}
	}
	stmt, ok := statement.(*sqlparser.DDL)
	if !ok {
		return &DDLPlan{Action: ""}
	}
	return &DDLPlan{
		Action: stmt.Action,
	}
}
144883
func (pq *PriorityQueue) cmpAsc(priority uint8) bool {
	return pq.order == ASC && priority < pq.curLevel
}
1066102
func (g *Generator) CmdType(doms []proto.Domain) {
	g.hasContent = true
	g.Printf(`
// CmdType is the type for CDP methods names.
type CmdType string

func (c CmdType) String() string {
	return string(c)
}

// Cmd methods.
const (`)
	for _, d := range doms {
		for _, c := range d.Commands {
			g.Printf("\n\t%s CmdType = %q", c.CmdName(d, true), d.Domain+"."+c.NameName)
		}
	}
	g.Printf("\n)\n")
}
823171
func (d *Directive) possibleParserDirective(line string) error {
	if d.processingComplete {
		return nil
	}

	tecMatch := tokenEscapeCommand.FindStringSubmatch(strings.ToLower(line))
	if len(tecMatch) != 0 {
		for i, n := range tokenEscapeCommand.SubexpNames() {
			if n == "escapechar" {
				if d.escapeSeen == true {
					return errors.New("only one escape parser directive can be used")
				}
				d.escapeSeen = true
				return d.setEscapeToken(tecMatch[i])
			}
		}
	}

	// TODO @jhowardmsft LCOW Support: Eventually this check can be removed,
	// but only recognise a platform token if running in LCOW mode.
	if system.LCOWSupported() {
		tpcMatch := tokenPlatformCommand.FindStringSubmatch(strings.ToLower(line))
		if len(tpcMatch) != 0 {
			for i, n := range tokenPlatformCommand.SubexpNames() {
				if n == "platform" {
					if d.platformSeen == true {
						return errors.New("only one platform parser directive can be used")
					}
					d.platformSeen = true
					return d.setPlatformToken(tpcMatch[i])
				}
			}
		}
	}

	d.processingComplete = true
	return nil
}
491160
func logAndExec(cmd string, args ...string) (string, error) {
	logger.Debugf("running: %s %s", cmd, strings.Join(args, " "))
	c := exec.Command(cmd, args...)
	output, err := c.CombinedOutput()
	if err != nil {
		output := strings.TrimSpace(string(output))
		if len(output) > 0 {
			err = errors.Annotate(err, output)
		}
	}
	return string(output), err
}
1046823
func cmdBuild() *subcommands.Command {
	return &subcommands.Command{
		Advanced:  true,
		UsageLine: "pkg-build [options]",
		ShortDesc: "builds a package instance file",
		LongDesc:  "Builds a package instance producing *.cipd file.",
		CommandRun: func() subcommands.CommandRun {
			c := &buildRun{}
			c.registerBaseFlags()
			c.inputOptions.registerFlags(&c.Flags)
			c.hashOptions.registerFlags(&c.Flags)
			c.Flags.StringVar(&c.outputFile, "out", "<path>", "Path to a file to write the final package to.")
			return c
		},
	}
}
869235
func (h *Client) UserLanguage(userLanguage string) *Client {
	h.userLanguage = userLanguage
	h.userLanguageSet = true
	return h
}
667903
func ExecCmd(cmdName string, args ...string) (string, string, error) {
	return ExecCmdDir("", cmdName, args...)
}