<commit_before>package handler

import (
	"bytes"
	"os"
	"sort"
	"strings"

	log "github.com/Sirupsen/logrus"
	"github.com/camptocamp/conplicity/util"
	"github.com/fgrehm/go-dockerpty"
	"github.com/fsouza/go-dockerclient"
	"github.com/jessevdk/go-flags"
)

type environment struct {
	Image              string   `short:"i" long:"image" description:"The duplicity docker image." env:"DUPLICITY_DOCKER_IMAGE" default:"camptocamp/duplicity:latest"`
	DuplicityTargetURL string   `short:"u" long:"url" description:"The duplicity target URL to push to." env:"DUPLICITY_TARGET_URL"`
	PushgatewayURL     string   `short:"g" long:"gateway-url" description:"The prometheus push gateway URL to use." env:"PUSHGATEWAY_URL"`
	AWSAccessKeyID     string   `long:"aws-access-key-id" description:"The AWS access key ID." env:"AWS_ACCESS_KEY_ID"`
	AWSSecretAccessKey string   `long:"aws-secret-key-id" description:"The AWS secret access key." env:"AWS_SECRET_ACCESS_KEY"`
	SwiftUsername      string   `long:"swift-username" description:"The Swift user name." env:"SWIFT_USERNAME"`
	SwiftPassword      string   `long:"swift-password" description:"The Swift password." env:"SWIFT_PASSWORD"`
	SwiftAuthURL       string   `long:"swift-auth_url" description:"The Swift auth URL." env:"SWIFT_AUTHURL"`
	SwiftTenantName    string   `long:"swift-tenant-name" description:"The Swift tenant name." env:"SWIFT_TENANTNAME"`
	SwiftRegionName    string   `long:"swift-region-name" description:"The Swift region name." env:"SWIFT_REGIONNAME"`
	FullIfOlderThan    string   `long:"full-if-older-than" description:"The number of days after which a full backup must be performed." env:"CONPLICITY_FULL_IF_OLDER_THAN" default:"15D"`
	RemoveOlderThan    string   `long:"remove-older-than" description:"The number days after which backups must be removed." env:"CONPLICITY_REMOVE_OLDER_THAN" default:"30D"`
	VolumesBlacklist   []string `short:"b" long:"blacklist" description:"Volumes to blacklist in backups." env:"CONPLICITY_VOLUMES_BLACKLIST"`
}

// Conplicity is the main handler struct
type Conplicity struct {
	*docker.Client
	*environment
	Hostname string
}

// Setup sets up a Conplicity struct
func (c *Conplicity) Setup() (err error) {
	c.getEnv()

	c.Hostname, err = os.Hostname()
	util.CheckErr(err, "Failed to get hostname: %v", 1)

	endpoint := "unix:///var/run/docker.sock"

	c.Client, err = docker.NewClient(endpoint)
	util.CheckErr(err, "Failed to create Docker client: %v", 1)

	err = c.pullImage()
	util.CheckErr(err, "Failed to pull image: %v", 1)

	return
}

func (c *Conplicity) getEnv() (err error) {
	c.environment = &environment{}
	parser := flags.NewParser(c.environment, flags.Default)
	if _, err = parser.Parse(); err != nil {
		os.Exit(1)
	}
	sort.Strings(c.VolumesBlacklist)
	return
}<commit_msg>Add --version<commit_after>package handler

import (
	"bytes"
	"fmt"
	"os"
	"sort"
	"strings"

	log "github.com/Sirupsen/logrus"
	"github.com/camptocamp/conplicity/util"
	"github.com/fgrehm/go-dockerpty"
	"github.com/fsouza/go-dockerclient"
	"github.com/jessevdk/go-flags"
)

const version = "0.8.1"

type environment struct {
	Version            bool     `short:"V" long:"version" description:"Display version."`
	Image              string   `short:"i" long:"image" description:"The duplicity docker image." env:"DUPLICITY_DOCKER_IMAGE" default:"camptocamp/duplicity:latest"`
	DuplicityTargetURL string   `short:"u" long:"url" description:"The duplicity target URL to push to." env:"DUPLICITY_TARGET_URL"`
	PushgatewayURL     string   `short:"g" long:"gateway-url" description:"The prometheus push gateway URL to use." env:"PUSHGATEWAY_URL"`
	AWSAccessKeyID     string   `long:"aws-access-key-id" description:"The AWS access key ID." env:"AWS_ACCESS_KEY_ID"`
	AWSSecretAccessKey string   `long:"aws-secret-key-id" description:"The AWS secret access key." env:"AWS_SECRET_ACCESS_KEY"`
	SwiftUsername      string   `long:"swift-username" description:"The Swift user name." env:"SWIFT_USERNAME"`
	SwiftPassword      string   `long:"swift-password" description:"The Swift password." env:"SWIFT_PASSWORD"`
	SwiftAuthURL       string   `long:"swift-auth_url" description:"The Swift auth URL." env:"SWIFT_AUTHURL"`
	SwiftTenantName    string   `long:"swift-tenant-name" description:"The Swift tenant name." env:"SWIFT_TENANTNAME"`
	SwiftRegionName    string   `long:"swift-region-name" description:"The Swift region name." env:"SWIFT_REGIONNAME"`
	FullIfOlderThan    string   `long:"full-if-older-than" description:"The number of days after which a full backup must be performed." env:"CONPLICITY_FULL_IF_OLDER_THAN" default:"15D"`
	RemoveOlderThan    string   `long:"remove-older-than" description:"The number days after which backups must be removed." env:"CONPLICITY_REMOVE_OLDER_THAN" default:"30D"`
	VolumesBlacklist   []string `short:"b" long:"blacklist" description:"Volumes to blacklist in backups." env:"CONPLICITY_VOLUMES_BLACKLIST"`
}

// Conplicity is the main handler struct
type Conplicity struct {
	*docker.Client
	*environment
	Hostname string
}

// Setup sets up a Conplicity struct
func (c *Conplicity) Setup() (err error) {
	c.getEnv()

	c.Hostname, err = os.Hostname()
	util.CheckErr(err, "Failed to get hostname: %v", 1)

	endpoint := "unix:///var/run/docker.sock"

	c.Client, err = docker.NewClient(endpoint)
	util.CheckErr(err, "Failed to create Docker client: %v", 1)

	err = c.pullImage()
	util.CheckErr(err, "Failed to pull image: %v", 1)

	return
}

func (c *Conplicity) getEnv() (err error) {
	c.environment = &environment{}
	parser := flags.NewParser(c.environment, flags.Default)
	if _, err = parser.Parse(); err != nil {
		os.Exit(1)
	}

	if c.environment.Version {
		fmt.Printf("Conplicity v%v\n", version)
		os.Exit(0)
	}

	sort.Strings(c.VolumesBlacklist)
	return
}
{'fraction_non_alphanumeric': 0.13012631943242775, 'fraction_numerical': 0.003460806367883717, 'mean_word_length': 4.964912280701754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '464598', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1916, 'n_words': 469}