Skip to content

Commit

Permalink
Make a single binary and alias scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
iychoi committed Jun 7, 2022
1 parent a7850a7 commit 9ddf69e
Show file tree
Hide file tree
Showing 22 changed files with 308 additions and 384 deletions.
42 changes: 19 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PKG=github.com/cyverse/gocommands
VERSION=v0.1.0
VERSION=v0.2.0
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS?="-X '${PKG}/commons.clientVersion=${VERSION}' -X '${PKG}/commons.gitCommit=${GIT_COMMIT}' -X '${PKG}/commons.buildDate=${BUILD_DATE}'"
Expand All @@ -12,75 +12,71 @@ GOPATH=$(shell go env GOPATH)
.PHONY: build
build:
mkdir -p bin
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/goinit ./cmd/goinit/goinit.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gols ./cmd/gols/gols.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/goget ./cmd/goget/goget.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/goput ./cmd/goput/goput.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gocd ./cmd/gocd/gocd.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gopwd ./cmd/gopwd/gopwd.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gomv ./cmd/gomv/gomv.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gocp ./cmd/gocp/gocp.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gorm ./cmd/gorm/gorm.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gormdir ./cmd/gormdir/gormdir.go
CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gomkdir ./cmd/gomkdir/gomkdir.go

CGO_ENABLED=0 go build -ldflags=${LDFLAGS} -o bin/gocmd ./cmd/*.go


.PHONY: build-release
build-release:
# i386_linux
mkdir -p release/i386_linux
cd install && ./prep-install-script.sh ../release/i386_linux && cd ..
cd build && ./build.sh linux 386 ../release/i386_linux ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/i386_linux && cd ..
CGO_ENABLED=0 GOARCH=386 GOOS=linux go build -ldflags=${LDFLAGS} -o release/i386_linux/gocmd cmd/*.go
cd release/i386_linux && tar cf gocommands_i386_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/i386_linux

# amd64_linux
mkdir -p release/amd64_linux
cd install && ./prep-install-script.sh ../release/amd64_linux && cd ..
cd build && ./build.sh linux amd64 ../release/amd64_linux ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/amd64_linux && cd ..
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags=${LDFLAGS} -o release/amd64_linux/gocmd cmd/*.go
cd release/amd64_linux && tar cf gocommands_amd64_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/amd64_linux

# arm_linux
mkdir -p release/arm_linux
cd install && ./prep-install-script.sh ../release/arm_linux && cd ..
cd build && ./build.sh linux arm ../release/arm_linux ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/arm_linux && cd ..
CGO_ENABLED=0 GOARCH=arm GOOS=linux go build -ldflags=${LDFLAGS} -o release/arm_linux/gocmd cmd/*.go
cd release/arm_linux && tar cf gocommands_arm_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/arm_linux

# arm64_linux
mkdir -p release/arm64_linux
cd install && ./prep-install-script.sh ../release/arm64_linux && cd ..
cd build && ./build.sh linux arm64 ../release/arm64_linux ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/arm64_linux && cd ..
CGO_ENABLED=0 GOARCH=arm64 GOOS=linux go build -ldflags=${LDFLAGS} -o release/arm64_linux/gocmd cmd/*.go
cd release/arm64_linux && tar cf gocommands_arm64_linux_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/arm64_linux

# amd64_darwin
mkdir -p release/amd64_darwin
cd install && ./prep-install-script.sh ../release/amd64_darwin && cd ..
cd build && ./build.sh darwin amd64 ../release/amd64_darwin ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/amd64_darwin && cd ..
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -ldflags=${LDFLAGS} -o release/amd64_darwin/gocmd cmd/*.go
cd release/amd64_darwin && tar cf gocommands_amd64_darwin_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/amd64_darwin

# arm64_darwin
mkdir -p release/arm64_darwin
cd install && ./prep-install-script.sh ../release/arm64_darwin && cd ..
cd build && ./build.sh darwin arm64 ../release/arm64_darwin ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/arm64_darwin && cd ..
CGO_ENABLED=0 GOARCH=arm64 GOOS=darwin go build -ldflags=${LDFLAGS} -o release/arm64_darwin/gocmd cmd/*.go
cd release/arm64_darwin && tar cf gocommands_arm64_darwin_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/arm64_darwin

# i386_windows
mkdir -p release/i386_windows
cd install && ./prep-install-script.sh ../release/i386_windows && cd ..
cd build && ./build.sh windows 386 ../release/i386_windows ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/i386_windows && cd ..
CGO_ENABLED=0 GOARCH=386 GOOS=windows go build -ldflags=${LDFLAGS} -o release/i386_windows/gocmd cmd/*.go
cd release/i386_windows && tar cf gocommands_i386_windows_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/i386_windows

# amd64_windows
mkdir -p release/amd64_windows
cd install && ./prep-install-script.sh ../release/amd64_windows && cd ..
cd build && ./build.sh windows amd64 ../release/amd64_windows ${LDFLAGS} && cd ..
cd install && ./prep-shortcut-script.sh ../release/amd64_windows && cd ..
CGO_ENABLED=0 GOARCH=amd64 GOOS=windows go build -ldflags=${LDFLAGS} -o release/amd64_windows/gocmd cmd/*.go
cd release/amd64_windows && tar cf gocommands_amd64_windows_${VERSION}.tar * && mv *.tar .. && cd ../..
rm -rf release/amd64_windows


16 changes: 0 additions & 16 deletions build/build.sh

This file was deleted.

40 changes: 19 additions & 21 deletions cmd/gopwd/gopwd.go → cmd/gocmd.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package main

import (
"fmt"
"os"

"github.com/cyverse/gocommands/cmd/subcmd"
"github.com/cyverse/gocommands/commons"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gopwd",
Short: "Print current working iRODS collection",
Long: `This prints current working iRODS collection.`,
Use: "gocmd [subcommand]",
Short: "Gocommands, a command-line iRODS client",
Long: `Gocommands, a command-line iRODS client.`,
RunE: processCommand,
}

Expand All @@ -36,17 +36,8 @@ func processCommand(command *cobra.Command, args []string) error {
return err
}

// handle local flags
_, err = commons.InputMissingFields()
if err != nil {
logger.Error(err)
return err
}

err = printCurrentWorkingDir()
if err != nil {
return err
}
// if nothing is given
commons.PrintHelp(command)

return nil
}
Expand All @@ -60,15 +51,22 @@ func main() {
// attach common flags
commons.SetCommonFlags(rootCmd)

// add sub commands
subcmd.AddInitCommand(rootCmd)
subcmd.AddPwdCommand(rootCmd)
subcmd.AddCdCommand(rootCmd)
subcmd.AddLsCommand(rootCmd)
subcmd.AddCpCommand(rootCmd)
subcmd.AddMvCommand(rootCmd)
subcmd.AddGetCommand(rootCmd)
subcmd.AddPutCommand(rootCmd)
subcmd.AddMkdirCommand(rootCmd)
subcmd.AddRmCommand(rootCmd)
subcmd.AddRmdirCommand(rootCmd)

err := Execute()
if err != nil {
logger.Fatal(err)
os.Exit(1)
}
}

func printCurrentWorkingDir() error {
cwd := commons.GetCWD()
fmt.Printf("%s\n", cwd)
return nil
}
41 changes: 12 additions & 29 deletions cmd/gocd/gocd.go → cmd/subcmd/gocd.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package main
package subcmd

import (
"fmt"
"os"

irodsclient_fs "github.com/cyverse/go-irodsclient/fs"
"github.com/cyverse/gocommands/commons"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gocd [collection1]",
var cdCmd = &cobra.Command{
Use: "cd [collection1]",
Short: "Change current working iRODS collection",
Long: `This changes current working iRODS collection.`,
RunE: processCommand,
RunE: processCdCommand,
}

func Execute() error {
return rootCmd.Execute()
func AddCdCommand(rootCmd *cobra.Command) {
// attach common flags
commons.SetCommonFlags(cdCmd)

rootCmd.AddCommand(cdCmd)
}

func processCommand(command *cobra.Command, args []string) error {
func processCdCommand(command *cobra.Command, args []string) error {
logger := log.WithFields(log.Fields{
"package": "main",
"function": "processCommand",
"function": "processCdCommand",
})

cont, err := commons.ProcessCommonFlags(command)
Expand All @@ -46,8 +47,7 @@ func processCommand(command *cobra.Command, args []string) error {

// Create a file system
account := commons.GetAccount()

filesystem, err := irodsclient_fs.NewFileSystemWithDefault(account, "gocommands-cd")
filesystem, err := commons.GetIRODSFSClient(account)
if err != nil {
return err
}
Expand All @@ -66,26 +66,9 @@ func processCommand(command *cobra.Command, args []string) error {
return err
}
}

return nil
}

func main() {
logger := log.WithFields(log.Fields{
"package": "main",
"function": "main",
})

// attach common flags
commons.SetCommonFlags(rootCmd)

err := Execute()
if err != nil {
logger.Fatal(err)
os.Exit(1)
}
}

func changeWorkingDir(filesystem *irodsclient_fs.FileSystem, collectionPath string) error {
logger := log.WithFields(log.Fields{
"package": "main",
Expand Down
43 changes: 14 additions & 29 deletions cmd/gocp/gocp.go → cmd/subcmd/gocp.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package main
package subcmd

import (
"fmt"
"os"
"path/filepath"
"strconv"

Expand All @@ -12,22 +11,26 @@ import (
"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gocp [data-object1] [data-object2] [collection1] ... [target collection]",
var cpCmd = &cobra.Command{
Use: "cp [data-object1] [data-object2] [collection1] ... [target collection]",
Short: "Copy iRODS data-objects or collections to target collection",
Long: `This copies iRODS data-objects or collections to the given target collection.`,
RunE: processCommand,
RunE: processCpCommand,
}

func Execute() error {
return rootCmd.Execute()
func AddCpCommand(rootCmd *cobra.Command) {
// attach common flags
commons.SetCommonFlags(cpCmd)

cpCmd.Flags().BoolP("recurse", "r", false, "Copy recursively")

rootCmd.AddCommand(cpCmd)
}

func processCommand(command *cobra.Command, args []string) error {
func processCpCommand(command *cobra.Command, args []string) error {
logger := log.WithFields(log.Fields{
"package": "main",
"function": "processCommand",
"function": "processCpCommand",
})

cont, err := commons.ProcessCommonFlags(command)
Expand Down Expand Up @@ -57,8 +60,7 @@ func processCommand(command *cobra.Command, args []string) error {

// Create a file system
account := commons.GetAccount()

filesystem, err := irodsclient_fs.NewFileSystemWithDefault(account, "gocommands-cp")
filesystem, err := commons.GetIRODSFSClient(account)
if err != nil {
return err
}
Expand Down Expand Up @@ -88,23 +90,6 @@ func processCommand(command *cobra.Command, args []string) error {
return nil
}

func main() {
logger := log.WithFields(log.Fields{
"package": "main",
"function": "main",
})

// attach common flags
commons.SetCommonFlags(rootCmd)
rootCmd.Flags().BoolP("recurse", "r", false, "Copy recursively")

err := Execute()
if err != nil {
logger.Fatal(err)
os.Exit(1)
}
}

func copyOne(filesystem *irodsclient_fs.FileSystem, sourcePath string, targetPath string, recurse bool) error {
logger := log.WithFields(log.Fields{
"package": "main",
Expand Down
Loading

0 comments on commit 9ddf69e

Please sign in to comment.