Skip to content

Commit

Permalink
a bunch of small grammar fixes for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed May 13, 2023
1 parent d62ce2c commit 8310446
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
10 changes: 5 additions & 5 deletions cmd/spot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func run(opts options) error {
return errs.ErrorOrNil()
}

if opts.TaskName != "" { // run single task
if opts.TaskName != "" { // run a single task
for _, targetName := range targetsForTask(opts, opts.TaskName, conf) {
if err := runTaskForTarget(ctx, r, opts.TaskName, targetName); err != nil {
return err
Expand Down Expand Up @@ -217,8 +217,8 @@ func runTaskForTarget(ctx context.Context, r runner.Process, taskName, targetNam
return nil
}

// get list of targets for task. Usually ths is just list of all targets from command line,
// however if task has targets defined AND cli has default target, then only those targets will be used.
// get the list of targets for the task. Usually this is just a list of all targets from the command line,
// however, if the task has targets defined AND cli has the default target, then only those targets will be used.
func targetsForTask(opts options, taskName string, conf *config.PlayBook) []string {
if len(opts.Targets) > 1 || (len(opts.Targets) == 1 && opts.Targets[0] != "default") {
// non-default target specified on command line
Expand Down Expand Up @@ -267,7 +267,7 @@ func makeSecretsProvider(sopts SecretsProvider) (config.SecretsProvider, error)
return &secrets.NoOpProvider{}, nil
}

// get ssh key from cli or playbook. if no key provided, use default ~/.ssh/id_rsa
// get ssh key from cli or playbook. if no key is provided, use default ~/.ssh/id_rsa
func sshKey(opts options, conf *config.PlayBook, provider userInfoProvider) (key string, err error) {
sshKey := opts.SSHKey
if sshKey == "" && (conf == nil || conf.SSHKey != "") { // no key provided in cli
Expand All @@ -287,7 +287,7 @@ func sshKey(opts options, conf *config.PlayBook, provider userInfoProvider) (key
return sshKey, nil
}

// get ssh user from cli or playbook. if no user provided, use current user from os
// get ssh user from cli or playbook. if no user is provided, use current user from os
func sshUser(opts options, conf *config.PlayBook, provider userInfoProvider) (res string, err error) {
sshUser := opts.SSHUser
if sshUser == "" && (conf == nil || conf.User != "") { // no user provided in cli
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (cmd *Cmd) GetWait() (command string, rdr io.Reader) {
return cmd.scriptCommand(cmd.Wait.Command), nil
}

// scriptCommand concatenates all script line in commands into one a string to be executed by shell.
// scriptCommand concatenates all script lines in commands into one a string to be executed by shell.
// Empty string is returned if no script is defined.
func (cmd *Cmd) scriptCommand(inp string) string {
if inp == "" {
Expand Down Expand Up @@ -134,7 +134,7 @@ func (cmd *Cmd) scriptCommand(inp string) string {
return res
}

// scriptFile returns a reader for script file. All the line in the command used as a script, with hashbang,
// scriptFile returns a reader for script file. All the lines in the command used as a script, with hashbang,
// set -e and environment variables.
func (cmd *Cmd) scriptFile(inp string) (r io.Reader) {
var buf bytes.Buffer
Expand Down Expand Up @@ -170,7 +170,7 @@ func (cmd *Cmd) scriptFile(inp string) (r io.Reader) {

// if the line in the script is an export, add it to the list of exports
// this is done to be able to print the variables set by the script to the console after the script is executed
// those variables can be used by the caller to set environment variables for the next commands
// the caller can use those variables to set environment variables for the next commands
if strings.HasPrefix(c, "export") {
expKey := strings.TrimPrefix(c, "export")
expElems := strings.Split(expKey, "=")
Expand Down Expand Up @@ -205,7 +205,7 @@ func (cmd *Cmd) genEnv() []string {
return envs
}

// getSecrets returns a sorted list of secrets key from the secrets slice (part of the command)
// getSecrets returns a sorted list of secrets keys from the secrets slice (part of the command)
func (cmd *Cmd) getSecrets() []string {
secrets := []string{}
for _, k := range cmd.Options.Secrets {
Expand Down Expand Up @@ -296,7 +296,7 @@ func (cmd *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

// validate checks if a Cmd has exactly one command type set (script, copy, mcopy, delete, sync, or wait)
// validate checks if a Cmd has the exactly one command type set (script, copy, mcopy, delete, sync, or wait)
// and returns an error if there are either multiple command types set or none set.
func (cmd *Cmd) validate() error {
cmdTypes := []struct {
Expand Down
13 changes: 6 additions & 7 deletions pkg/config/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

//go:generate moq -out mocks/secrets.go -pkg mocks -skip-ensure -fmt goimports . secretsProvider:SecretProvider

// PlayBook defines top-level config object
// PlayBook defines the top-level config object
type PlayBook struct {
User string `yaml:"user" toml:"user"` // ssh user
SSHKey string `yaml:"ssh_key" toml:"ssh_key"` // ssh key
Expand Down Expand Up @@ -320,7 +320,6 @@ func (p *PlayBook) Task(name string) (*Task, error) {
}

// TargetHosts returns target hosts for given target name.
// After it gets destinations from targetHosts(name) it applies overrides of user, set default port 22 if needed.
func (p *PlayBook) TargetHosts(name string) ([]Destination, error) {

userOverride := func(u string) string {
Expand All @@ -344,7 +343,7 @@ func (p *PlayBook) TargetHosts(name string) ([]Destination, error) {

for i, h := range res {
if h.Port == 0 {
h.Port = 22 // default port is 22 if not set
h.Port = 22 // the default port is 22 if not set
}
h.User = userOverride(h.User)
res[i] = h
Expand Down Expand Up @@ -446,7 +445,7 @@ func (p *PlayBook) loadInventory(loc string) (*InventoryData, error) {
for _, gr := range data.Groups {
for i := range gr {
if gr[i].Port == 0 {
gr[i].Port = 22 // default port is 22 if not set
gr[i].Port = 22 // the default port is 22 if not set
}
if gr[i].User == "" {
gr[i].User = p.User // default user is playbook's user or override, if not set by inventory
Expand Down Expand Up @@ -522,19 +521,19 @@ func (p *PlayBook) loadSecrets() error {
p.secrets = make(map[string]string)
}

// collect Secrets from all command's, retrieve them from provider and store in Secrets map
// collect Secrets from all command's, retrieve them from provider and store in the secrets map
for _, t := range p.Tasks {
for i, c := range t.Commands {
for _, key := range c.Options.Secrets {
val, err := p.secretsProvider.Get(key)
if err != nil {
return fmt.Errorf("can't get secret %q defined in task %q, command %q: %w", key, t.Name, c.Name, err)
}
p.secrets[key] = val // store secret in Secrets map of playbook
p.secrets[key] = val // store secret in the secrets map of playbook
if c.Secrets == nil {
c.Secrets = make(map[string]string)
}
c.Secrets[key] = val // store secret in Secrets map of command
c.Secrets[key] = val // store secret in the secrets map of command
}
t.Commands[i] = c
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (tg *targetExtractor) destinationsFromInventory(name string) ([]Destination
}
}

// check if name looks like host:port
// check if the name looks like host:port
if strings.Contains(name, ":") {
elems := strings.Split(name, ":")
port, err := strconv.Atoi(elems[1])
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Interface interface {
Close() error
}

// StdOutLogWriter is a writer that writes log with a prefix and a log level.
// StdOutLogWriter is a writer that writes to log with a prefix and a log level.
type StdOutLogWriter struct {
prefix string
level string
Expand Down
8 changes: 4 additions & 4 deletions pkg/executor/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (ex *Remote) Upload(ctx context.Context, local, remote string, mkdir bool)
return fmt.Errorf("source file %q not found", local)
}

// upload each file matching the glob pattern. If no glob pattern is found the file is matched as is
// upload each file matching the glob pattern. If no glob pattern is found, the file is matched as is
for _, match := range matches {
remoteFile := remote
if len(matches) > 1 { // if there are multiple files, treat remote as a directory
Expand Down Expand Up @@ -152,7 +152,7 @@ func (ex *Remote) Sync(ctx context.Context, localDir, remoteDir string, del bool
}

// Delete file on remote server. Recursively if recursive is true.
// if file or directory does not exist, returns nil, i.e. no error.
// if a file or directory does not exist, returns nil, i.e. no error.
func (ex *Remote) Delete(ctx context.Context, remoteFile string, recursive bool) (err error) {
if ex.client == nil {
return fmt.Errorf("client is not connected")
Expand Down Expand Up @@ -228,7 +228,7 @@ func (ex *Remote) Delete(ctx context.Context, remoteFile string, recursive bool)
return nil
}

// sshRun executes command on remote server. context close sends interrupt signal to remote process.
// sshRun executes command on remote server. context close sends interrupt signal to the remote process.
func (ex *Remote) sshRun(ctx context.Context, client *ssh.Client, command string, verbose bool) (out []string, err error) {
log.Printf("[DEBUG] run ssh command %q on %s", command, client.RemoteAddr().String())
session, err := client.NewSession()
Expand All @@ -238,7 +238,7 @@ func (ex *Remote) sshRun(ctx context.Context, client *ssh.Client, command string
defer session.Close()

outLog, errLog := MakeOutAndErrWriters(ex.hostAddr, ex.hostName, verbose, ex.secrets)
outLog.Write([]byte(command)) //nolint
outLog.Write([]byte(command)) // nolint

var stdoutBuf bytes.Buffer
mwr := io.MultiWriter(outLog, &stdoutBuf)
Expand Down
3 changes: 2 additions & 1 deletion pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func (p *Process) runTaskOnHost(ctx context.Context, tsk *config.Task, hostAddr,
return count, nil
}

// execCommand executes a single command on a target host. It detects command type based on the fields what are set.
// execCommand executes a single command on a target host.
// It detects the command type based on the fields what are set.
// Even if multiple fields for multiple commands are set, only one will be executed.
func (p *Process) execCommand(ctx context.Context, ec execCmd) (details string, vars map[string]string, err error) {
switch {
Expand Down

0 comments on commit 8310446

Please sign in to comment.