add import preferences (-preferences)
This commit is contained in:
parent
24db172462
commit
6bde84b7e3
3 changed files with 107 additions and 28 deletions
71
main.go
71
main.go
|
@ -12,15 +12,18 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
var srcUser string
|
||||
var destUser string
|
||||
var password string
|
||||
var fromUser string
|
||||
var fromPassword string
|
||||
var toUser string
|
||||
var toPassword string
|
||||
var pdsUrl string
|
||||
var fromPdsUrl string
|
||||
var dryrun bool = false
|
||||
var verbose bool = false
|
||||
|
||||
var importProfile bool = false
|
||||
var importFollows bool = false
|
||||
var importPreferences bool = false
|
||||
|
||||
i := 1
|
||||
for {
|
||||
|
@ -40,13 +43,17 @@ func main() {
|
|||
|
||||
switch os.Args[i][1:] {
|
||||
case "from":
|
||||
i, srcUser = getValue(i)
|
||||
i, fromUser = getValue(i)
|
||||
case "frompass":
|
||||
i, fromPassword = getValue(i)
|
||||
case "to":
|
||||
i, destUser = getValue(i)
|
||||
case "pass":
|
||||
i, password = getValue(i)
|
||||
i, toUser = getValue(i)
|
||||
case "topass":
|
||||
i, toPassword = getValue(i)
|
||||
case "pds":
|
||||
i, pdsUrl = getValue(i)
|
||||
case "frompds":
|
||||
i, fromPdsUrl = getValue(i)
|
||||
case "dryrun":
|
||||
dryrun = true
|
||||
case "v":
|
||||
|
@ -55,19 +62,21 @@ func main() {
|
|||
importProfile = true
|
||||
case "follows":
|
||||
importFollows = true
|
||||
case "preferences":
|
||||
importPreferences = true
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
if srcUser == "" {
|
||||
if fromUser == "" {
|
||||
fmt.Fprintf(os.Stderr, "missing required argument -from.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
if destUser == "" {
|
||||
if toUser == "" {
|
||||
fmt.Fprintf(os.Stderr, "missing required argument -to.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
if password == "" {
|
||||
if toPassword == "" {
|
||||
fmt.Fprintf(os.Stderr, "missing required argument -pass.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -75,27 +84,49 @@ func main() {
|
|||
fmt.Fprintf(os.Stderr, "missing required argument -pds.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
if fromPdsUrl == "" { fromPdsUrl = pdsUrl }
|
||||
|
||||
if !importProfile && !importFollows {
|
||||
if !(importProfile || importFollows || importPreferences) {
|
||||
fmt.Fprintf(os.Stderr, "no action was specified.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
session, err := CreateSession(pdsUrl, destUser, password)
|
||||
var fromSession *AtprotoSession
|
||||
if !(fromPassword == "" || fromPdsUrl == "") {
|
||||
var err error
|
||||
fromSession, err = CreateSession(fromPdsUrl, fromUser, fromPassword)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to create session for source account: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
toSession, err := CreateSession(pdsUrl, toUser, toPassword)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to create session: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "failed to create session for destination account: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if importProfile {
|
||||
err := ImportProfile(session, pdsUrl, srcUser, dryrun, verbose)
|
||||
err := ImportProfile(toSession, pdsUrl, fromUser, dryrun, verbose)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to import profile: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if importPreferences {
|
||||
if fromSession == nil {
|
||||
fmt.Fprintf(os.Stderr, "-frompass and -frompds must be provided for a preferences import.\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
err := ImportPreferences(fromSession, toSession, pdsUrl, dryrun, verbose)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to import preferences: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if importFollows {
|
||||
err := ImportFollows(session, pdsUrl, srcUser, dryrun, verbose)
|
||||
err := ImportFollows(toSession, pdsUrl, fromUser, dryrun, verbose)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed to import follows: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -108,16 +139,18 @@ func printHelp() {
|
|||
`usage: %s <arguments...> <imports...>
|
||||
|
||||
required arguments:
|
||||
-from <handle>: the account to import follow records from.
|
||||
-to <handle>: the account to import follow records to.
|
||||
-pass <password>: the password of the `+"`to`"+` account.
|
||||
-pds <pds-url>: the full https:// url of the `+"`to`"+` account's PDS.
|
||||
-from <identifier>: the source account handle or DID.
|
||||
-frompass <password>: the source account password.
|
||||
-to <identifier>: the destination account handle or DID.
|
||||
-topass <password>: the destination account password.
|
||||
-pds <pds-url>: the full https:// url of the destination account's PDS.
|
||||
|
||||
imports (at least one required):
|
||||
-profile: imports the account profile, including avatar, banner, display name, and description.
|
||||
-follows: imports the following list of the account.
|
||||
|
||||
optional arguments:
|
||||
-frompds <pds-url>: the source account's PDS url (defaults to the value of -pds).
|
||||
-dryrun: does not import follow records; good for sanity testing!
|
||||
-v: verbose output
|
||||
-help: shows this help message.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue