forked from TrueCloudLab/rclone
Use pflag for gnu style flags
This commit is contained in:
parent
4990535d1b
commit
a628bef9c2
3 changed files with 21 additions and 20 deletions
|
@ -17,7 +17,6 @@ package drive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
@ -31,6 +30,7 @@ import (
|
||||||
"code.google.com/p/goauth2/oauth"
|
"code.google.com/p/goauth2/oauth"
|
||||||
"code.google.com/p/google-api-go-client/drive/v2"
|
"code.google.com/p/google-api-go-client/drive/v2"
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
|
"github.com/ogier/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
|
@ -43,7 +43,7 @@ const (
|
||||||
// Globals
|
// Globals
|
||||||
var (
|
var (
|
||||||
// Flags
|
// Flags
|
||||||
driveFullList = flag.Bool("drive-full-list", true, "Use a full listing for directory list. More data but usually quicker.")
|
driveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register with Fs
|
// Register with Fs
|
||||||
|
|
14
fs/config.go
14
fs/config.go
|
@ -3,7 +3,6 @@ package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -15,6 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Unknwon/goconfig"
|
"github.com/Unknwon/goconfig"
|
||||||
|
"github.com/ogier/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -32,12 +32,12 @@ var (
|
||||||
// Global config
|
// Global config
|
||||||
Config = &ConfigInfo{}
|
Config = &ConfigInfo{}
|
||||||
// Flags
|
// Flags
|
||||||
verbose = flag.Bool("verbose", false, "Print lots more stuff")
|
verbose = pflag.BoolP("verbose", "v", false, "Print lots more stuff")
|
||||||
quiet = flag.Bool("quiet", false, "Print as little stuff as possible")
|
quiet = pflag.BoolP("quiet", "q", false, "Print as little stuff as possible")
|
||||||
modifyWindow = flag.Duration("modify-window", time.Nanosecond, "Max time diff to be considered the same")
|
modifyWindow = pflag.DurationP("modify-window", "", time.Nanosecond, "Max time diff to be considered the same")
|
||||||
checkers = flag.Int("checkers", 8, "Number of checkers to run in parallel.")
|
checkers = pflag.IntP("checkers", "", 8, "Number of checkers to run in parallel.")
|
||||||
transfers = flag.Int("transfers", 4, "Number of file transfers to run in parallel.")
|
transfers = pflag.IntP("transfers", "", 4, "Number of file transfers to run in parallel.")
|
||||||
configFile = flag.String("config", ConfigPath, "Config file.")
|
configFile = pflag.StringP("config", "", ConfigPath, "Config file.")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Filesystem config options
|
// Filesystem config options
|
||||||
|
|
23
rclone.go
23
rclone.go
|
@ -4,7 +4,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -14,6 +13,8 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ogier/pflag"
|
||||||
|
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
// Active file systems
|
// Active file systems
|
||||||
_ "github.com/ncw/rclone/drive"
|
_ "github.com/ncw/rclone/drive"
|
||||||
|
@ -25,9 +26,9 @@ import (
|
||||||
// Globals
|
// Globals
|
||||||
var (
|
var (
|
||||||
// Flags
|
// Flags
|
||||||
cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to file")
|
cpuprofile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file")
|
||||||
dry_run = flag.Bool("dry-run", false, "Do a trial run with no permanent changes")
|
dry_run = pflag.BoolP("dry-run", "n", false, "Do a trial run with no permanent changes")
|
||||||
statsInterval = flag.Duration("stats", time.Minute*1, "Interval to print stats")
|
statsInterval = pflag.DurationP("stats", "", time.Minute*1, "Interval to print stats")
|
||||||
)
|
)
|
||||||
|
|
||||||
// A pair of fs.Objects
|
// A pair of fs.Objects
|
||||||
|
@ -131,7 +132,7 @@ func DeleteFiles(to_be_deleted fs.ObjectsChan) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for dst := range to_be_deleted {
|
for dst := range to_be_deleted {
|
||||||
if *dry_run {
|
if *dry_run {
|
||||||
fs.Debug(dst, "Not deleting as -dry-run")
|
fs.Debug(dst, "Not deleting as --dry-run")
|
||||||
} else {
|
} else {
|
||||||
fs.Stats.Checking(dst)
|
fs.Stats.Checking(dst)
|
||||||
err := dst.Remove()
|
err := dst.Remove()
|
||||||
|
@ -339,7 +340,7 @@ func mkdir(fdst, fsrc fs.Fs) {
|
||||||
// Removes a container but not if not empty
|
// Removes a container but not if not empty
|
||||||
func rmdir(fdst, fsrc fs.Fs) {
|
func rmdir(fdst, fsrc fs.Fs) {
|
||||||
if *dry_run {
|
if *dry_run {
|
||||||
log.Printf("Not deleting %s as -dry-run", fdst)
|
log.Printf("Not deleting %s as --dry-run", fdst)
|
||||||
} else {
|
} else {
|
||||||
err := fdst.Rmdir()
|
err := fdst.Rmdir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -414,7 +415,7 @@ var Commands = []Command{
|
||||||
unchanged files, testing first by modification time then by
|
unchanged files, testing first by modification time then by
|
||||||
MD5SUM. Deletes any files that exist in source that don't
|
MD5SUM. Deletes any files that exist in source that don't
|
||||||
exist in destination. Since this can cause data loss, test
|
exist in destination. Since this can cause data loss, test
|
||||||
first with the -dry-run flag.`,
|
first with the --dry-run flag.`,
|
||||||
Run: Sync,
|
Run: Sync,
|
||||||
MinArgs: 2,
|
MinArgs: 2,
|
||||||
MaxArgs: 2,
|
MaxArgs: 2,
|
||||||
|
@ -507,7 +508,7 @@ Subcommands:
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "Options:\n")
|
fmt.Fprintf(os.Stderr, "Options:\n")
|
||||||
flag.PrintDefaults()
|
pflag.PrintDefaults()
|
||||||
fmt.Fprintf(os.Stderr, `
|
fmt.Fprintf(os.Stderr, `
|
||||||
It is only necessary to use a unique prefix of the subcommand, eg 'up' for 'upload'.
|
It is only necessary to use a unique prefix of the subcommand, eg 'up' for 'upload'.
|
||||||
`)
|
`)
|
||||||
|
@ -521,9 +522,9 @@ func fatal(message string, args ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Usage = syntaxError
|
pflag.Usage = syntaxError
|
||||||
flag.Parse()
|
pflag.Parse()
|
||||||
args := flag.Args()
|
args := pflag.Args()
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
fs.LoadConfig()
|
fs.LoadConfig()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue