From fad308366f3e8da2fc03a84511d821c3aad27aa3 Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Fri, 27 May 2016 15:58:17 -0600 Subject: [PATCH] commands_{lock,locks,unlock}: allow custom --remote specification --- commands/command_lock.go | 15 +++++++++++++++ commands/command_locks.go | 5 +++++ commands/command_unlock.go | 5 +++++ 3 files changed, 25 insertions(+) diff --git a/commands/command_lock.go b/commands/command_lock.go index 4726146d..ecdc4b01 100644 --- a/commands/command_lock.go +++ b/commands/command_lock.go @@ -2,11 +2,22 @@ package commands import ( "github.com/github/git-lfs/api" + "github.com/github/git-lfs/config" "github.com/github/git-lfs/git" "github.com/spf13/cobra" ) var ( + lockRemote string + lockRemoteHelp = "specify which remote to use when interacting with locks" + + // TODO(taylor): consider making this (and the above flag) a property of + // some parent-command, or another similarly less ugly way of handling + // this + setLockRemoteFor = func(c *config.Configuration) { + c.CurrentRemote = lockRemote + } + lockCmd = &cobra.Command{ Use: "lock", Run: lockCommand, @@ -14,6 +25,8 @@ var ( ) func lockCommand(cmd *cobra.Command, args []string) { + setLockRemoteFor(config.Config) + if len(args) == 0 { Print("Usage: git lfs lock ") return @@ -45,5 +58,7 @@ func lockCommand(cmd *cobra.Command, args []string) { } func init() { + lockCmd.Flags().StringVarP(&lockRemote, "remote", "r", config.Config.CurrentRemote, lockRemoteHelp) + RootCmd.AddCommand(lockCmd) } diff --git a/commands/command_locks.go b/commands/command_locks.go index b1fb8872..c21faf46 100644 --- a/commands/command_locks.go +++ b/commands/command_locks.go @@ -2,6 +2,7 @@ package commands import ( "github.com/github/git-lfs/api" + "github.com/github/git-lfs/config" "github.com/spf13/cobra" ) @@ -14,6 +15,8 @@ var ( ) func locksCommand(cmd *cobra.Command, args []string) { + setLockRemoteFor(config.Config) + s, resp := API.Locks.Search(&api.LockSearchRequest{ Filters: locksCmdFlags.Filters(), Cursor: locksCmdFlags.Cursor, @@ -32,6 +35,8 @@ func locksCommand(cmd *cobra.Command, args []string) { } func init() { + locksCmd.Flags().StringVarP(&lockRemote, "remote", "r", config.Config.CurrentRemote, lockRemoteHelp) + locksCmd.Flags().StringVarP(&locksCmdFlags.Path, "path", "p", "", "filter locks results matching a particular path") locksCmd.Flags().StringVarP(&locksCmdFlags.Id, "id", "i", "", "filter locks results matching a particular ID") locksCmd.Flags().StringVarP(&locksCmdFlags.Cursor, "cursor", "c", "", "cursor for last seen lock result") diff --git a/commands/command_unlock.go b/commands/command_unlock.go index f6719e7f..0c46068a 100644 --- a/commands/command_unlock.go +++ b/commands/command_unlock.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/github/git-lfs/api" + "github.com/github/git-lfs/config" "github.com/spf13/cobra" ) @@ -25,6 +26,8 @@ var ( ) func unlockCommand(cmd *cobra.Command, args []string) { + setLockRemoteFor(config.Config) + var id string if len(args) != 0 { if matchedId, err := lockIdFromPath(args[0]); err != nil { @@ -84,6 +87,8 @@ func lockIdFromPath(path string) (string, error) { } func init() { + unlockCmd.Flags().StringVarP(&lockRemote, "remote", "r", config.Config.CurrentRemote, lockRemoteHelp) + unlockCmd.Flags().StringVarP(&unlockId, "id", "i", "", "unlock a lock by its ID") RootCmd.AddCommand(unlockCmd)