Beispiel #1
0
func slackImportCmdF(cmd *cobra.Command, args []string) error {
	initDBCommandContextCobra(cmd)

	if len(args) != 2 {
		return errors.New("Incorrect number of arguments.")
	}

	team := getTeamFromTeamArg(args[0])
	if team == nil {
		return errors.New("Unable to find team '" + args[0] + "'")
	}

	fileReader, err := os.Open(args[1])
	if err != nil {
		return err
	}
	defer fileReader.Close()

	fileInfo, err := fileReader.Stat()
	if err != nil {
		return err
	}

	CommandPrettyPrintln("Running Slack Import. This may take a long time for large teams or teams with many messages.")

	api.SlackImport(fileReader, fileInfo.Size(), team.Id)

	CommandPrettyPrintln("Finished Slack Import.")

	return nil
}
Beispiel #2
0
func cmdSlackImport() {
	if flagCmdSlackImport {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name")
			flag.Usage()
			os.Exit(1)
		}

		if len(flagImportArchive) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -import_archive")
			flag.Usage()
			os.Exit(1)
		}

		var team *model.Team
		if result := <-api.Srv.Store.Team().GetByName(flagTeamName); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			team = result.Data.(*model.Team)
		}

		fileReader, err := os.Open(flagImportArchive)
		if err != nil {
			l4g.Error("%v", err)
			flushLogAndExit(1)
		}
		defer fileReader.Close()

		fileInfo, err := fileReader.Stat()
		if err != nil {
			l4g.Error("%v", err)
			flushLogAndExit(1)
		}

		fmt.Fprintln(os.Stdout, "Running Slack Import. This may take a long time for large teams or teams with many messages.")

		api.SlackImport(fileReader, fileInfo.Size(), team.Id)

		flushLogAndExit(0)
	}
}