<commit_before>//Docket Client
//Author: <NAME>
//<NAME>
package main

//push
//pull
//images
//-h[ost]
//-p[ort]

import (
	"fmt"
	"github.com/alecthomas/kingpin"
)

var (
	host = kingpin.Flag("host", "Set host of docket registry.").Short('h').Default("127.0.0.1").IP()
	port = kingpin.Flag("port", "Set port of docket registry.").Short('p').Default("9090").Int()

	push      = kingpin.Command("push", "Push to the docket registry.")
	pushFlag  = push.Flag("test", "Push flag").Bool()
	pushImage = push.Arg("push", "Image to push.").Required().String()
)

func applyPush(image string) error {
	fmt.Println("image = ", image)
	fmt.Println("host = ", host)
	fmt.Println("port = ", port)
	return nil
}

func main() {
	kingpin.CommandLine.Help = "Docket Client"
	switch kingpin.Parse() {
	case "push":
		kingpin.FatalIfError(applyPush((*pushImage)), "Pushing of image failed")
	}
}<commit_msg>finished checking image from docker images list, generating filename and exporting image to tarball<commit_after>//Docket Client
//Author: <NAME>
//<NAME>
package main

//push
//pull
//-h[ost]
//-p[ort]

import (
	"errors"
	"fmt"
	"github.com/alecthomas/kingpin"
	"github.com/fsouza/go-dockerclient"
	"os/exec"
	"regexp"
	"strings"
)

var (
	host = kingpin.Flag("host", "Set host of docket registry.").Short('h').Default("127.0.0.1").IP()
	port = kingpin.Flag("port", "Set port of docket registry.").Short('p').Default("9090").Int()

	push      = kingpin.Command("push", "Push to the docket registry.")
	pushImage = push.Arg("push", "Image to push.").Required().String()

	pull      = kingpin.Command("pull", "pull to the docket registry.")
	pullImage = pull.Arg("pull", "Image to pull.").Required().String()
)

func applyPush(image string) error {
	reg, err := regexp.Compile("[^A-Za-z0-9]+")
	if err != nil {
		return err
	}

	endpoint := "unix:///var/run/docker.sock"
	client, _ := docker.NewClient(endpoint)
	imgs, _ := client.ListImages(docker.ListImagesOptions{All: false})

	found := false
	tagId := ""
	filePath := ""

	for _, img := range imgs {
		tags := img.RepoTags
		for _, tag := range tags {
			if tag == image {
				found = true
				tagId = img.ID
				fmt.Println("Found image: ", image)
				fmt.Println("ID: ", img.ID)
				fmt.Println("RepoTags: ", img.RepoTags)
				fmt.Println("Created: ", img.Created)
				fmt.Println("Size: ", img.Size)
				fmt.Println("VirtualSize: ", img.VirtualSize)
				fmt.Println("ParentId: ", img.ParentID)
				safeImageName := reg.ReplaceAllString(image, "_")
				s := []string{"/tmp/", tagId, "_", safeImageName, ".tar"}
				filePath = strings.Join(s, "")
				break
			}
		}
	}
	if !found {
		return errors.New("Sorry the image could not be found.")
	}

	//Run export command
	//command invocation
	//run docker command save to tar ball in /tmp
	fmt.Println("Exporting image to tarball...")
	cmd := fmt.Sprintf("docker save %s > %s", image, filePath)
	output, err1 := exec.Command("sh", "-c", cmd).Output()
	if err1 != nil {
		return err1
	}

	fmt.Println("Successively exported tarball...")
	//file writing
	//making http post request with body contents
	//make post request with contents of tarball to docket registry

	return nil
}

func applyPull(image string) error {
	fmt.Println("image = ", image)
	fmt.Println("host = ", host)
	fmt.Println("port = ", port)
	return nil
}

func main() {
	kingpin.CommandLine.Help = "Docket Client"

	switch kingpin.Parse() {
	case "push":
		kingpin.FatalIfError(applyPush(*pushImage), "Pushing of image failed")
	case "pull":
		kingpin.FatalIfError(applyPush((*pushImage)), "Pushing of image failed")
	}
}
{'fraction_non_alphanumeric': 0.17895030709101062, 'fraction_numerical': 0.006979341150195421, 'mean_word_length': 3.7965194109772424, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1253226', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1237, 'n_words': 310}