package main import ( "fmt" "os" "slices" ) func main() { if len(os.Args) == 1 || slices.Contains(os.Args, "-help") { printHelp() os.Exit(0) } var srcUser string var destUser string var password string var pdsUrl string var dryrun bool = false var verbose bool = false var importProfile bool = false var importFollows bool = false i := 1 for { if i >= len(os.Args) { break } if os.Args[i][0] != '-' { fmt.Fprintf(os.Stderr, "unrecognised argument `%s`.\n", os.Args[i]) os.Exit(1) } getValue := func(i int) (int, string) { if i + 1 >= len(os.Args) { fmt.Fprintf(os.Stderr, "-%s requires a value.\n", os.Args[i]) os.Exit(1) } return i + 1, os.Args[i + 1] } switch os.Args[i][1:] { case "from": i, srcUser = getValue(i) case "to": i, destUser = getValue(i) case "pass": i, password = getValue(i) case "pds": i, pdsUrl = getValue(i) case "dryrun": dryrun = true case "v": verbose = true case "profile": importProfile = true case "follows": importFollows = true } i += 1 } if srcUser == "" { fmt.Fprintf(os.Stderr, "missing required argument -from.\n") os.Exit(1) } if destUser == "" { fmt.Fprintf(os.Stderr, "missing required argument -to.\n") os.Exit(1) } if password == "" { fmt.Fprintf(os.Stderr, "missing required argument -pass.\n") os.Exit(1) } if pdsUrl == "" { fmt.Fprintf(os.Stderr, "missing required argument -pds.\n") os.Exit(1) } if !importProfile && !importFollows { fmt.Fprintf(os.Stderr, "no action was specified.\n") os.Exit(1) } session, err := CreateSession(pdsUrl, destUser, password) if err != nil { fmt.Fprintf(os.Stderr, "failed to create session: %v\n", err) os.Exit(1) } if importProfile { err := ImportProfile(session, pdsUrl, srcUser, dryrun, verbose) if err != nil { fmt.Fprintf(os.Stderr, "failed to import profile: %v\n", err) os.Exit(1) } } if importFollows { err := ImportFollows(session, pdsUrl, srcUser, dryrun, verbose) if err != nil { fmt.Fprintf(os.Stderr, "failed to import follows: %v\n", err) os.Exit(1) } } } func printHelp() { fmt.Printf( `usage: %s required arguments: -from : the account to import follow records from. -to : the account to import follow records to. -pass : the password of the `+"`to`"+` account. -pds : the full https:// url of the `+"`to`"+` 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: -dryrun: does not import follow records; good for sanity testing! -v: verbose output -help: shows this help message. `, os.Args[0], ) }