mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-03 15:47:23 -04:00
Implement entry/directory renaming/moving
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package cli
|
||||
|
||||
import "github.com/rwinkhart/MUTN/src/offline"
|
||||
|
||||
// RenameCli renames an entry at oldLocation to a new location (user input)
|
||||
func RenameCli(oldLocation string) {
|
||||
// ensure targetLocation exists
|
||||
offline.TargetIsFile(oldLocation, true, 0)
|
||||
|
||||
// prompt user for new location and rename
|
||||
newLocation := offline.EntryRoot + offline.PathSeparator + input("New location:")
|
||||
offline.Rename(oldLocation, newLocation)
|
||||
|
||||
// exit is done from offline.Rename
|
||||
}
|
||||
@@ -37,7 +37,7 @@ This program comes with absolutely no warranty; type "mutn version" for details.
|
||||
note/-n Add a note entry
|
||||
folder/-f Add a new folder for entries
|
||||
edit:
|
||||
rename/relocate/-r Rename or relocate an entry
|
||||
rename/-r Rename or relocate an entry
|
||||
username/-u Change the username of an entry
|
||||
password/-p Change the password of an entry
|
||||
url/-l Change the url attached to an entry
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package offline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Rename renames oldLocation to newLocation
|
||||
func Rename(oldLocation string, newLocation string) {
|
||||
// ensure newLocation does not exist
|
||||
_, isAccessible := TargetIsFile(newLocation, false, 0)
|
||||
if isAccessible {
|
||||
fmt.Println(AnsiError + "\"" + newLocation + "\" already exists" + AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// rename oldLocation to newLocation
|
||||
err := os.Rename(oldLocation, newLocation)
|
||||
if err != nil {
|
||||
fmt.Println(AnsiError + "Failed to rename - does the target containing directory exists?" + AnsiReset)
|
||||
}
|
||||
|
||||
// TODO If in online mode, check if oldLocation is a directory and rename it on the server
|
||||
os.Exit(0)
|
||||
}
|
||||
Reference in New Issue
Block a user