github.com/cyverse/go-irodsclient@v0.13.2/examples/make_dir/make_dir.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/cyverse/go-irodsclient/fs"
     9  	"github.com/cyverse/go-irodsclient/irods/types"
    10  
    11  	log "github.com/sirupsen/logrus"
    12  )
    13  
    14  func main() {
    15  	logger := log.WithFields(log.Fields{
    16  		"package":  "main",
    17  		"function": "main",
    18  	})
    19  
    20  	recurse := false
    21  	// Parse cli parameters
    22  	flag.BoolVar(&recurse, "p", false, "create parent directories if not exist")
    23  	flag.Parse()
    24  	args := flag.Args()
    25  
    26  	if len(args) != 1 {
    27  		fmt.Fprintf(os.Stderr, "Give an iRODS path!\n")
    28  		os.Exit(1)
    29  	}
    30  
    31  	inputPath := args[0]
    32  
    33  	// Read account configuration from YAML file
    34  	yaml, err := os.ReadFile("account.yml")
    35  	if err != nil {
    36  		logger.Error(err)
    37  		panic(err)
    38  	}
    39  
    40  	account, err := types.CreateIRODSAccountFromYAML(yaml)
    41  	if err != nil {
    42  		logger.Error(err)
    43  		panic(err)
    44  	}
    45  
    46  	logger.Debugf("Account : %v", account.MaskSensitiveData())
    47  
    48  	// Create a file system
    49  	appName := "make_dir"
    50  	filesystem, err := fs.NewFileSystemWithDefault(account, appName)
    51  	if err != nil {
    52  		logger.Error(err)
    53  		panic(err)
    54  	}
    55  
    56  	defer filesystem.Release()
    57  
    58  	err = filesystem.MakeDir(inputPath, recurse)
    59  	if err != nil {
    60  		logger.Error(err)
    61  		panic(err)
    62  	}
    63  
    64  	if filesystem.ExistsDir(inputPath) {
    65  		fmt.Printf("Successfully made dir %s\n", inputPath)
    66  	} else {
    67  		fmt.Printf("Could not make dir %s\n", inputPath)
    68  	}
    69  }