<commit_before>package command

import (
	"archive/tar"
	"archive/zip"
	"bytes"
	"compress/gzip"
	"context"
	"crypto/md5"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"time"

	"github.com/chrislusf/seaweedfs/weed/glog"
	"github.com/chrislusf/seaweedfs/weed/util"
	"golang.org/x/net/context/ctxhttp"
)

//copied from https://github.com/restic/restic/tree/master/internal/selfupdate

// Release collects data about a single release on GitHub.
type Release struct {
	Name        string    `json:"name"`
	TagName     string    `json:"tag_name"`
	Draft       bool      `json:"draft"`
	PreRelease  bool      `json:"prerelease"`
	PublishedAt time.Time `json:"published_at"`
	Assets      []Asset   `json:"assets"`

	Version string `json:"-"` // set manually in the code
}

// Asset is a file uploaded and attached to a release.
type Asset struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	URL  string `json:"url"`
}

const githubAPITimeout = 30 * time.Second

// githubError is returned by the GitHub API, e.g. for rate-limiting.
type githubError struct {
	Message string
}

//default version is not full version
var isFullVersion = false

var (
	updateOpt UpdateOptions
)

type UpdateOptions struct {
	dir     *string
	name    *string
	Version *string
}

func init() {
	path, _ := os.Executable()
	_, name := filepath.Split(path)
	updateOpt.dir = cmdUpdate.Flag.String("dir", filepath.Dir(path), "directory to save new weed.")
	updateOpt.name = cmdUpdate.Flag.String("name", name, "name of new weed. On windows, name shouldn't be same to the orignial name.")
	updateOpt.Version = cmdUpdate.Flag.String("version", "0", "specific version of weed you want to download. If not specified, get the latest version.")
	cmdUpdate.Run = runUpdate
}

var cmdUpdate = &Command{
	UsageLine: "weed update -dir=/path/to/dir -name=name -version=x.xx",
	Short:     "get latest or specific version from https://github.com/chrislusf/seaweedfs",
	Long:      `get latest or specific version from https://github.com/chrislusf/seaweedfs`,
}

func runUpdate(cmd *Command, args []string) bool {
	path, _ := os.Executable()
	_, name := filepath.Split(path)
<commit_msg>remove "weed" from UsageLine, or weed will not show usage of weed update<commit_after>package command

import (
	"archive/tar"
	"archive/zip"
	"bytes"
	"compress/gzip"
	"context"
	"crypto/md5"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
	"runtime"
	"strings"
	"time"

	"github.com/chrislusf/seaweedfs/weed/glog"
	"github.com/chrislusf/seaweedfs/weed/util"
	"golang.org/x/net/context/ctxhttp"
)

//copied from https://github.com/restic/restic/tree/master/internal/selfupdate

// Release collects data about a single release on GitHub.
type Release struct {
	Name        string    `json:"name"`
	TagName     string    `json:"tag_name"`
	Draft       bool      `json:"draft"`
	PreRelease  bool      `json:"prerelease"`
	PublishedAt time.Time `json:"published_at"`
	Assets      []Asset   `json:"assets"`

	Version string `json:"-"` // set manually in the code
}

// Asset is a file uploaded and attached to a release.
type Asset struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	URL  string `json:"url"`
}

const githubAPITimeout = 30 * time.Second

// githubError is returned by the GitHub API, e.g. for rate-limiting.
type githubError struct {
	Message string
}

//default version is not full version
var isFullVersion = false

var (
	updateOpt UpdateOptions
)

type UpdateOptions struct {
	dir     *string
	name    *string
	Version *string
}

func init() {
	path, _ := os.Executable()
	_, name := filepath.Split(path)
	updateOpt.dir = cmdUpdate.Flag.String("dir", filepath.Dir(path), "directory to save new weed.")
	updateOpt.name = cmdUpdate.Flag.String("name", name, "name of new weed. On windows, name shouldn't be same to the orignial name.")
	updateOpt.Version = cmdUpdate.Flag.String("version", "0", "specific version of weed you want to download. If not specified, get the latest version.")
	cmdUpdate.Run = runUpdate
}

var cmdUpdate = &Command{
	UsageLine: "update [-dir=/path/to/dir] [-name=name] [-version=x.xx]",
	Short:     "get latest or specific version from https://github.com/chrislusf/seaweedfs",
	Long:      `get latest or specific version from https://github.com/chrislusf/seaweedfs`,
}

func runUpdate(cmd *Command, args []string) bool {
	path, _ := os.Executable()
	_, name := filepath.Split(path)

{'fraction_non_alphanumeric': 0.1322222222222222, 'fraction_numerical': 0.0017777777777777779, 'mean_word_length': 3.8087606837606836, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '319080', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1525, 'n_words': 435}