github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/cmd/go/internal/script/conds.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  // DefaultConds returns a set of broadly useful script conditions.
     8  //
     9  // Run the 'help' command within a script engine to view a list of the available
    10  // conditions.
    11  func DefaultConds() map[string]Cond
    12  
    13  // Condition returns a Cond with the given summary and evaluation function.
    14  func Condition(summary string, eval func(*State) (bool, error)) Cond
    15  
    16  // PrefixCondition returns a Cond with the given summary and evaluation function.
    17  func PrefixCondition(summary string, eval func(*State, string) (bool, error)) Cond
    18  
    19  // BoolCondition returns a Cond with the given truth value and summary.
    20  // The Cond rejects the use of condition suffixes.
    21  func BoolCondition(summary string, v bool) Cond
    22  
    23  // OnceCondition returns a Cond that calls eval the first time the condition is
    24  // evaluated. Future calls reuse the same result.
    25  //
    26  // The eval function is not passed a *State because the condition is cached
    27  // across all execution states and must not vary by state.
    28  func OnceCondition(summary string, eval func() (bool, error)) Cond
    29  
    30  // CachedCondition is like Condition but only calls eval the first time the
    31  // condition is evaluated for a given suffix.
    32  // Future calls with the same suffix reuse the earlier result.
    33  //
    34  // The eval function is not passed a *State because the condition is cached
    35  // across all execution states and must not vary by state.
    36  func CachedCondition(summary string, eval func(string) (bool, error)) Cond