github.com/gogf/gf/v2@v2.7.4/os/gproc/gproc_must.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gproc
     8  
     9  import (
    10  	"context"
    11  	"io"
    12  )
    13  
    14  // MustShell performs as Shell, but it panics if any error occurs.
    15  func MustShell(ctx context.Context, cmd string, out io.Writer, in io.Reader) {
    16  	if err := Shell(ctx, cmd, out, in); err != nil {
    17  		panic(err)
    18  	}
    19  }
    20  
    21  // MustShellRun performs as ShellRun, but it panics if any error occurs.
    22  func MustShellRun(ctx context.Context, cmd string) {
    23  	if err := ShellRun(ctx, cmd); err != nil {
    24  		panic(err)
    25  	}
    26  }
    27  
    28  // MustShellExec performs as ShellExec, but it panics if any error occurs.
    29  func MustShellExec(ctx context.Context, cmd string, environment ...[]string) string {
    30  	result, err := ShellExec(ctx, cmd, environment...)
    31  	if err != nil {
    32  		panic(err)
    33  	}
    34  	return result
    35  }