1
mirror of https://github.com/rclone/rclone synced 2024-11-21 22:50:16 +01:00

Use pflag for gnu style flags

This commit is contained in:
Nick Craig-Wood 2014-03-27 16:55:29 +00:00
parent 4990535d1b
commit a628bef9c2
3 changed files with 21 additions and 20 deletions

View File

@ -17,7 +17,6 @@ package drive
import (
"encoding/json"
"flag"
"fmt"
"io"
"log"
@ -31,6 +30,7 @@ import (
"code.google.com/p/goauth2/oauth"
"code.google.com/p/google-api-go-client/drive/v2"
"github.com/ncw/rclone/fs"
"github.com/ogier/pflag"
)
// Constants
@ -43,7 +43,7 @@ const (
// Globals
var (
// 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

View File

@ -3,7 +3,6 @@ package fs
import (
"bufio"
"flag"
"fmt"
"log"
"os"
@ -15,6 +14,7 @@ import (
"time"
"github.com/Unknwon/goconfig"
"github.com/ogier/pflag"
)
const (
@ -32,12 +32,12 @@ var (
// Global config
Config = &ConfigInfo{}
// Flags
verbose = flag.Bool("verbose", false, "Print lots more stuff")
quiet = flag.Bool("quiet", false, "Print as little stuff as possible")
modifyWindow = flag.Duration("modify-window", time.Nanosecond, "Max time diff to be considered the same")
checkers = flag.Int("checkers", 8, "Number of checkers to run in parallel.")
transfers = flag.Int("transfers", 4, "Number of file transfers to run in parallel.")
configFile = flag.String("config", ConfigPath, "Config file.")
verbose = pflag.BoolP("verbose", "v", false, "Print lots more stuff")
quiet = pflag.BoolP("quiet", "q", false, "Print as little stuff as possible")
modifyWindow = pflag.DurationP("modify-window", "", time.Nanosecond, "Max time diff to be considered the same")
checkers = pflag.IntP("checkers", "", 8, "Number of checkers to run in parallel.")
transfers = pflag.IntP("transfers", "", 4, "Number of file transfers to run in parallel.")
configFile = pflag.StringP("config", "", ConfigPath, "Config file.")
)
// Filesystem config options

View File

@ -4,7 +4,6 @@
package main
import (
"flag"
"fmt"
"log"
"os"
@ -14,6 +13,8 @@ import (
"sync"
"time"
"github.com/ogier/pflag"
"github.com/ncw/rclone/fs"
// Active file systems
_ "github.com/ncw/rclone/drive"
@ -25,9 +26,9 @@ import (
// Globals
var (
// Flags
cpuprofile = flag.String("cpuprofile", "", "Write cpu profile to file")
dry_run = flag.Bool("dry-run", false, "Do a trial run with no permanent changes")
statsInterval = flag.Duration("stats", time.Minute*1, "Interval to print stats")
cpuprofile = pflag.StringP("cpuprofile", "", "", "Write cpu profile to file")
dry_run = pflag.BoolP("dry-run", "n", false, "Do a trial run with no permanent changes")
statsInterval = pflag.DurationP("stats", "", time.Minute*1, "Interval to print stats")
)
// A pair of fs.Objects
@ -131,7 +132,7 @@ func DeleteFiles(to_be_deleted fs.ObjectsChan) {
defer wg.Done()
for dst := range to_be_deleted {
if *dry_run {
fs.Debug(dst, "Not deleting as -dry-run")
fs.Debug(dst, "Not deleting as --dry-run")
} else {
fs.Stats.Checking(dst)
err := dst.Remove()
@ -339,7 +340,7 @@ func mkdir(fdst, fsrc fs.Fs) {
// Removes a container but not if not empty
func rmdir(fdst, fsrc fs.Fs) {
if *dry_run {
log.Printf("Not deleting %s as -dry-run", fdst)
log.Printf("Not deleting %s as --dry-run", fdst)
} else {
err := fdst.Rmdir()
if err != nil {
@ -414,7 +415,7 @@ var Commands = []Command{
unchanged files, testing first by modification time then by
MD5SUM. Deletes any files that exist in source that don't
exist in destination. Since this can cause data loss, test
first with the -dry-run flag.`,
first with the --dry-run flag.`,
Run: Sync,
MinArgs: 2,
MaxArgs: 2,
@ -507,7 +508,7 @@ Subcommands:
}
fmt.Fprintf(os.Stderr, "Options:\n")
flag.PrintDefaults()
pflag.PrintDefaults()
fmt.Fprintf(os.Stderr, `
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() {
flag.Usage = syntaxError
flag.Parse()
args := flag.Args()
pflag.Usage = syntaxError
pflag.Parse()
args := pflag.Args()
runtime.GOMAXPROCS(runtime.NumCPU())
fs.LoadConfig()