sigs.k8s.io/release-sdk@v0.11.1-0.20240417074027-8061fb5e4952/osc/osc.go (about) 1 /* 2 Copyright 2023 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package osc 18 19 import ( 20 "fmt" 21 22 "sigs.k8s.io/release-utils/command" 23 ) 24 25 const ( 26 // OSCExecutable is the name of the OpenBuildService CLI executable 27 OSCExecutable = "osc" 28 ) 29 30 // PreCheck checks if all requirements are fulfilled to run this package and 31 // all sub-packages 32 func PreCheck() error { 33 for _, e := range []string{ 34 OSCExecutable, 35 } { 36 if !command.Available(e) { 37 return fmt.Errorf( 38 "%s executable is not available in $PATH", e, 39 ) 40 } 41 } 42 43 return nil 44 } 45 46 // OSC can be used to run a 'osc' command 47 func OSC(workDir string, args ...string) error { 48 return command.NewWithWorkDir(workDir, OSCExecutable, args...).RunSilentSuccess() 49 } 50 51 // Output can be used to run a 'osc' command while capturing its output 52 func Output(workDir string, args ...string) (string, error) { 53 stream, err := command.NewWithWorkDir(workDir, OSCExecutable, args...).RunSilentSuccessOutput() 54 if err != nil { 55 return "", fmt.Errorf("executing %s: %w", OSCExecutable, err) 56 } 57 return stream.OutputTrimNL(), nil 58 } 59 60 // Status can be used to run a 'osc' command while capturing its status 61 func Status(workDir string, args ...string) (*command.Status, error) { 62 return command.NewWithWorkDir(workDir, OSCExecutable, args...).Run() 63 }