Added cli package
This commit is contained in:
		
							parent
							
								
									92b93abb13
								
							
						
					
					
						commit
						9d8e6e8e24
					
				
							
								
								
									
										26
									
								
								cli/cli.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								cli/cli.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
			
		||||
// Package cli provides utilities for writing command line utilities that
 | 
			
		||||
// interact with services.
 | 
			
		||||
package cli
 | 
			
		||||
 | 
			
		||||
import "os"
 | 
			
		||||
import "fmt"
 | 
			
		||||
import "flag"
 | 
			
		||||
import "strings"
 | 
			
		||||
 | 
			
		||||
// Sayf is like Printf, but prints the program name before the message. This is
 | 
			
		||||
// used for printing messages and errors.
 | 
			
		||||
func Sayf (format string, values ...any) {
 | 
			
		||||
	Printf(os.Args[0] + ": " + format, values...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Printf prints to stderr.
 | 
			
		||||
func Printf (format string, values ...any) {
 | 
			
		||||
	fmt.Fprintf(flag.CommandLine.Output(), format, values...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ServiceUser returns the system user that corresponds to the given service
 | 
			
		||||
// name. This is not necissarily equivalent Hnakra user, although it is good
 | 
			
		||||
// practice to have a 1:1 correspondance between them.
 | 
			
		||||
func ServiceUser (service string) string {
 | 
			
		||||
	return "hn-" + strings.ToLower(service)
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user