github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/script/cmds.go (about)

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package script
     6  
     7  import (
     8  	"github.com/shogo82148/std/os/exec"
     9  	"github.com/shogo82148/std/time"
    10  )
    11  
    12  // DefaultCmds returns a set of broadly useful script commands.
    13  //
    14  // Run the 'help' command within a script engine to view a list of the available
    15  // commands.
    16  func DefaultCmds() map[string]Cmd
    17  
    18  // Command returns a new Cmd with a Usage method that returns a copy of the
    19  // given CmdUsage and a Run method calls the given function.
    20  func Command(usage CmdUsage, run func(*State, ...string) (WaitFunc, error)) Cmd
    21  
    22  // Cat writes the concatenated contents of the named file(s) to the script's
    23  // stdout buffer.
    24  func Cat() Cmd
    25  
    26  // Cd changes the current working directory.
    27  func Cd() Cmd
    28  
    29  // Chmod changes the permissions of a file or a directory..
    30  func Chmod() Cmd
    31  
    32  // Cmp compares the contents of two files, or the contents of either the
    33  // "stdout" or "stderr" buffer and a file, returning a non-nil error if the
    34  // contents differ.
    35  func Cmp() Cmd
    36  
    37  // Cmpenv is like Compare, but also performs environment substitutions
    38  // on the contents of both arguments.
    39  func Cmpenv() Cmd
    40  
    41  // Cp copies one or more files to a new location.
    42  func Cp() Cmd
    43  
    44  // Echo writes its arguments to stdout, followed by a newline.
    45  func Echo() Cmd
    46  
    47  // Env sets or logs the values of environment variables.
    48  //
    49  // With no arguments, Env reports all variables in the environment.
    50  // "key=value" arguments set variables, and arguments without "="
    51  // cause the corresponding value to be printed to the stdout buffer.
    52  func Env() Cmd
    53  
    54  // Exec runs an arbitrary executable as a subprocess.
    55  //
    56  // When the Script's context is canceled, Exec sends the interrupt signal, then
    57  // waits for up to the given delay for the subprocess to flush output before
    58  // terminating it with os.Kill.
    59  func Exec(cancel func(*exec.Cmd) error, waitDelay time.Duration) Cmd
    60  
    61  // Exists checks that the named file(s) exist.
    62  func Exists() Cmd
    63  
    64  // Grep checks that file content matches a regexp.
    65  // Like stdout/stderr and unlike Unix grep, it accepts Go regexp syntax.
    66  //
    67  // Grep does not modify the State's stdout or stderr buffers.
    68  // (Its output goes to the script log, not stdout.)
    69  func Grep() Cmd
    70  
    71  // Help writes command documentation to the script log.
    72  func Help() Cmd
    73  
    74  // Mkdir creates a directory and any needed parent directories.
    75  func Mkdir() Cmd
    76  
    77  // Mv renames an existing file or directory to a new path.
    78  func Mv() Cmd
    79  
    80  // Program returns a new command that runs the named program, found from the
    81  // host process's PATH (not looked up in the script's PATH).
    82  func Program(name string, cancel func(*exec.Cmd) error, waitDelay time.Duration) Cmd
    83  
    84  // Replace replaces all occurrences of a string in a file with another string.
    85  func Replace() Cmd
    86  
    87  // Rm removes a file or directory.
    88  //
    89  // If a directory, Rm also recursively removes that directory's
    90  // contents.
    91  func Rm() Cmd
    92  
    93  // Sleep sleeps for the given Go duration or until the script's context is
    94  // canceled, whichever happens first.
    95  func Sleep() Cmd
    96  
    97  // Stderr searches for a regular expression in the stderr buffer.
    98  func Stderr() Cmd
    99  
   100  // Stdout searches for a regular expression in the stdout buffer.
   101  func Stdout() Cmd
   102  
   103  // Stop returns a sentinel error that causes script execution to halt
   104  // and s.Execute to return with a nil error.
   105  func Stop() Cmd
   106  
   107  // Symlink creates a symbolic link.
   108  func Symlink() Cmd
   109  
   110  // Wait waits for the completion of background commands.
   111  //
   112  // When Wait returns, the stdout and stderr buffers contain the concatenation of
   113  // the background commands' respective outputs in the order in which those
   114  // commands were started.
   115  func Wait() Cmd