// Initialize allows TokenCommand to plug itself into the CLI parser
436029
func (c *TokenCommand) Initialize(app *kingpin.Application, config *service.Config) {
	c.config = config

	tokens := app.Command("tokens", "List or revoke invitation tokens")

	// tctl tokens add ..."
	c.tokenAdd = tokens.Command("add", "Create a invitation token")
	c.tokenAdd.Flag("type", "Type of token to add").Required().StringVar(&c.tokenType)
	c.tokenAdd.Flag("value", "Value of token to add").StringVar(&c.value)
	c.tokenAdd.Flag("ttl", fmt.Sprintf("Set expiration time for token, default is %v hour, maximum is %v hours",
		int(defaults.SignupTokenTTL/time.Hour), int(defaults.MaxSignupTokenTTL/time.Hour))).
		Default(fmt.Sprintf("%v", defaults.SignupTokenTTL)).DurationVar(&c.ttl)

	// "tctl tokens rm ..."
	c.tokenDel = tokens.Command("rm", "Delete/revoke an invitation token").Alias("del")
	c.tokenDel.Arg("token", "Token to delete").StringVar(&c.value)

	// "tctl tokens ls"
	c.tokenList = tokens.Command("ls", "List node and user invitation tokens")
	c.tokenList.Flag("format", "Output format, 'text' or 'json'").Hidden().Default(teleport.Text).StringVar(&c.format)
}
1230060
func (c *modelCredentialCommand) Init(args []string) error {
	if len(args) != 2 {
		return errors.Errorf("Usage: juju set-credential [options] <cloud name> <credential name>")
	}
	if !names.IsValidCloud(args[0]) {
		return errors.NotValidf("cloud name %q", args[0])
	}
	if !names.IsValidCloudCredentialName(args[1]) {
		return errors.NotValidf("cloud credential name %q", args[1])
	}
	c.cloud = args[0]
	c.credential = args[1]
	return nil
}
1176799
func Initialize(env *pflag.Flag) (*Configuration, error) {
	c := &Configuration{}

	path, err := getAppPath()
	if err != nil {
		return nil, err
	}
	c.AppPath = path

	c.AppName = getAppName(c.AppPath)
	c.AppEnvName = strmangle.EnvAppName(c.AppName)
	c.ActiveEnv = getActiveEnv(c.AppPath, c.AppName)
	// If ActiveEnv is not set via env var or config file,
	// OR the user has passed in an override value through a flag,
	// then set it to the flag value.
	if env != nil && (c.ActiveEnv == "" || env.Changed) {
		c.ActiveEnv = env.Value.String()
	}
	c.ModeViper = NewModeViper(c.AppPath, c.AppEnvName, c.ActiveEnv)

	return c, nil
}
188613
func (t *SubprocessTest) initialize(ctx context.Context) (err error) {
	// Initialize the context.
	t.Ctx = ctx

	// Set up a temporary directory.
	t.Dir, err = ioutil.TempDir("", "sample_test")
	if err != nil {
		err = fmt.Errorf("TempDir: %v", err)
		return
	}

	// Build/read the mount_sample tool.
	toolContents, err := getToolContents()
	if err != nil {
		err = fmt.Errorf("getTooltoolContents: %v", err)
		return
	}

	// Create a temporary file to hold the contents of the tool.
	toolFile, err := ioutil.TempFile("", "sample_test")
	if err != nil {
		err = fmt.Errorf("TempFile: %v", err)
		return
	}

	defer toolFile.Close()

	// Ensure that it is deleted when we leave.
	toolPath := toolFile.Name()
	defer os.Remove(toolPath)

	// Write out the tool contents and make them executable.
	if _, err = toolFile.Write(toolContents); err != nil {
		err = fmt.Errorf("toolFile.Write: %v", err)
		return
	}

	if err = toolFile.Chmod(0500); err != nil {
		err = fmt.Errorf("toolFile.Chmod: %v", err)
		return
	}

	// Close the tool file to prevent "text file busy" errors below.
	err = toolFile.Close()
	toolFile = nil
	if err != nil {
		err = fmt.Errorf("toolFile.Close: %v", err)
		return
	}

	// Set up basic args for the subprocess.
	args := []string{
		"--type",
		t.MountType,
		"--mount_point",
		t.Dir,
	}

	args = append(args, t.MountFlags...)

	// Set up a pipe for the "ready" status.
	readyReader, readyWriter, err := os.Pipe()
	if err != nil {
		err = fmt.Errorf("Pipe: %v", err)
		return
	}

	defer readyReader.Close()
	defer readyWriter.Close()

	t.MountFiles["ready_file"] = readyWriter

	// Set up inherited files and appropriate flags.
	var extraFiles []*os.File
	for flag, file := range t.MountFiles {
		// Cf. os/exec.Cmd.ExtraFiles
		fd := 3 + len(extraFiles)

		extraFiles = append(extraFiles, file)
		args = append(args, "--"+flag)
		args = append(args, fmt.Sprintf("%d", fd))
	}

	// Set up a command.
	var stderr bytes.Buffer
	mountCmd := exec.Command(toolPath, args...)
	mountCmd.Stderr = &stderr
	mountCmd.ExtraFiles = extraFiles

	// Handle debug mode.
	if *fDebug {
		mountCmd.Stderr = os.Stderr
		mountCmd.Args = append(mountCmd.Args, "--debug")
	}

	// Start the command.
	if err = mountCmd.Start(); err != nil {
		err = fmt.Errorf("mountCmd.Start: %v", err)
		return
	}

	// Launch a goroutine that waits for it and returns its status.
	mountSampleErr := make(chan error, 1)
	go waitForMountSample(mountCmd, mountSampleErr, &stderr)

	// Wait for the tool to say the file system is ready. In parallel, watch for
	// the tool to fail.
	readyChan := make(chan struct{}, 1)
	go waitForReady(readyReader, readyChan)

	select {
	case <-readyChan:
	case err = <-mountSampleErr:
		return
	}

	// TearDown is no responsible for joining.
	t.mountSampleErr = mountSampleErr

	return
}
725518
func (i *PluginInitializer) Initialize(plugin admission.Interface) {
	if wants, ok := plugin.(WantsCloudConfig); ok {
		wants.SetCloudConfig(i.cloudConfig)
	}

	if wants, ok := plugin.(WantsRESTMapper); ok {
		wants.SetRESTMapper(i.restMapper)
	}

	if wants, ok := plugin.(WantsQuotaConfiguration); ok {
		wants.SetQuotaConfiguration(i.quotaConfiguration)
	}
}
315398
func (c *listCommand) Init(args []string) (err error) {
	return cmd.CheckEmpty(args)
}
740449
func (d *Document) Initialize() {
	d.WordFrequency = make(map[string]int)
	for i, paragraph := range strings.Split(d.Content, "\n\n") {
		for _, s := range d.SentenceTokenizer.Tokenize(paragraph) {
			wordCount := d.NumWords
			d.NumSentences++
			words := []Word{}
			for _, word := range d.WordTokenizer.Tokenize(s) {
				word = strings.TrimSpace(word)
				if len(word) == 0 {
					continue
				}
				d.NumCharacters += countChars(word)
				if _, found := d.WordFrequency[word]; found {
					d.WordFrequency[word]++
				} else {
					d.WordFrequency[word] = 1
				}
				syllables := Syllables(word)
				words = append(words, Word{Text: word, Syllables: syllables})
				d.NumSyllables += float64(syllables)
				if syllables > 2 {
					d.NumPolysylWords++
				}
				if isComplex(word, syllables) {
					d.NumComplexWords++
				}
				d.NumWords++
			}
			d.Sentences = append(d.Sentences, Sentence{
				Text:      strings.TrimSpace(s),
				Length:    int(d.NumWords - wordCount),
				Words:     words,
				Paragraph: i})
		}
		d.NumParagraphs++
	}
}
1130174
func (processor *processor) Initialize() error {
	err := processor.Resource.CallFindOne(processor.Result, processor.MetaValues, processor.Context)
	processor.checkSkipLeft(err)
	return err
}
1010817
func (c *configCommand) Init(args []string) error {
	if len(args) == 0 || len(strings.Split(args[0], "=")) > 1 {
		return errors.New("no application name specified")
	}

	if err := c.validateGeneration(); err != nil {
		return errors.Trace(err)
	}

	// If there are arguments provided to reset, we turn it into a slice of
	// strings and verify them. If there is one or more valid keys to reset and
	// no other errors initializing the command, c.resetDefaults will be called
	// in c.Run.
	if err := c.parseResetKeys(); err != nil {
		return errors.Trace(err)
	}

	c.applicationName = args[0]
	args = args[1:]

	switch len(args) {
	case 0:
		return c.handleZeroArgs()
	case 1:
		return c.handleOneArg(args)
	default:
		return c.handleArgs(args)
	}
}
1126532
func (c *enableCommand) Init(args []string) error {
	if len(args) < 1 {
		return errors.Errorf("missing command set (%s)", validTargets)
	}
	c.target, args = args[0], args[1:]
	target, ok := toAPIValue[c.target]
	if !ok {
		return errors.Errorf("bad command set, valid options: %s", validTargets)
	}
	c.target = target
	return cmd.CheckEmpty(args)
}
1273803
func (c *config) initialize(prefixFlag string) {
	// Local container map to query by expanded name
	containerMap := make(map[string]*container)
	for rawName, container := range c.RawContainers {
		container.RawName = rawName
		containerMap[container.Name()] = container
	}
	// Local hooks map to query by expanded name
	hooksMap := make(map[string]hooks)
	for hooksRawName, hooks := range c.RawHooks {
		hooksMap[expandEnv(hooksRawName)] = hooks
	}
	// Groups
	c.groups = make(map[string][]string)
	for groupRawName, rawNames := range c.RawGroups {
		groupName := expandEnv(groupRawName)
		for _, rawName := range rawNames {
			c.groups[groupName] = append(c.groups[groupName], expandEnv(rawName))
		}
		if hooks, ok := hooksMap[groupName]; ok {
			// attach group-defined hooks to the group containers
			for _, name := range c.groups[groupName] {
				if overriden := containerMap[name].hooks.CopyFrom(hooks); overriden {
					panic(StatusError{fmt.Errorf("Multiple conflicting hooks inherited from groups for container `%s`", name), 64})
				}
			}
		}
	}
	// Cmds
	c.cmds = make(map[string][]string)
	for cmdRawName, rawCmd := range c.RawCmds {
		cmdName := expandEnv(cmdRawName)
		c.cmds[cmdName] = stringSlice(rawCmd)
	}
	// Container map
	c.containerMap = make(map[string]Container)
	for name, container := range containerMap {
		if hooks, ok := hooksMap[name]; ok {
			// attach container-defined hooks, overriding potential group-inherited hooks
			container.hooks.CopyFrom(hooks)
		}
		c.containerMap[name] = container
	}

	c.determinePrefix(prefixFlag)
	c.setNetworkMap()
	c.setVolumeMap()
	c.setAcceleratedMountMap()
}
1330232
func (c *createWalletCommand) Init(args []string) error {
	if len(args) < 2 {
		return errors.New("name and value required")
	}
	c.Name, c.Value = args[0], args[1]
	if _, err := strconv.ParseInt(c.Value, 10, 32); err != nil {
		return errors.New("wallet value needs to be a whole number")
	}
	return c.CommandBase.Init(args[2:])
}
703955
func (l *lexer) tokenize() {
	for l.state = lexData; l.state != nil; {
		l.state = l.state(l)
	}
}
264247
func (s *LocalService) Initialize(ctx contextAPI.Local) error {
	if ctx.Identifier().MSPID != s.mspID {
		return errors.Errorf("expecting context for MSP [%s] but got [%s]", s.mspID, ctx.Identifier().MSPID)
	}
	return s.service.initialize(ctx)
}
848160
func (c *leaderGetCommand) Init(args []string) error {
	c.key = ""
	if len(args) == 0 {
		return nil
	}
	key := args[0]
	if key == "-" {
		key = ""
	} else if strings.Contains(key, "=") {
		return errors.Errorf("invalid key %q", key)
	}
	c.key = key
	return cmd.CheckEmpty(args[1:])
}
1226546
func (agent *Agent) initialize(ctx context.Context) (context.Context, error) {
	ctx, err := agent.configureLogging(ctx)
	if err != nil {
		return ctx, err
	}
	if err = agent.configureMonitoring(ctx); err != nil {
		return ctx, err
	}

	// TODO(smut): Remove fallback on metadata server.
	if agent.server == "" {
		agent.server, err = metadata.Get("instance/attributes/machine_provider_server")
		if err != nil {
			return ctx, err
		}
	}
	if agent.serviceAccount == "" {
		agent.serviceAccount, err = metadata.Get("instance/attributes/machine_service_account")
		if err != nil {
			return ctx, err
		}
	}

	options := auth.Options{
		GCEAccountName:         agent.serviceAccount,
		ServiceAccountJSONPath: auth.GCEServiceAccount,
	}
	agent.client, err = auth.NewAuthenticator(ctx, auth.SilentLogin, options).Client()
	if err != nil {
		return ctx, err
	}
	metadataClient := metadata.NewClient(agent.client)
	agent.hostname, err = metadataClient.InstanceName()
	if err != nil {
		return ctx, err
	}
	agent.mp, err = getClient(ctx, agent.client, agent.server)
	if err != nil {
		return ctx, err
	}
	return ctx, nil
}
243987
func (c *commandBase) Initialize(params *Parameters) {
	c.p = params
	c.f.Register(c.GetFlags(), params)
}