Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

As a GitHub user, perhaps you have tried to change your GitHub avatar and realized there is a 1MB limit for images you can upload. Git Fit's purpose is to provide a tool in your command line (CLI) to compress your avatar while maintaining high quality output.

> NOTE!
> GitHub does not allow updating avatars through the GitHub API. GitHub avatars are generated and hosted from Gravatar (https://gravatar.com). The only other option is to use Gravatar's API endpoint to upload new avatar images (https://api.gravatar.com/v3/me/avatars).

- [ ] **TO DO: Connect to Gravatar API to update avatars.**

## useful gravatar links:

1. https://docs.gravatar.com/rest/getting-started/
2. https://gravatar.com/developers/console

## using the tool in its current state:
## using the tool

gitfit -input input.jpeg -output output.jpeg -maxsize <max bytes> -quality <1-100 for jpeg> -v [for verbose output]

Expand Down
28 changes: 14 additions & 14 deletions cmd/gitfit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Config struct {

// main() - entry point
func main() {
cfg := parseFlags()
cfg := parseFlags(os.Args[1:])
showUsage, err := validateConfig(cfg)

if showUsage {
Expand All @@ -49,28 +49,29 @@ func main() {
}

// parseFlags() - extract flags into a Config struct
func parseFlags() *Config {
func parseFlags(args []string) *Config {
fs := flag.NewFlagSet("gitfit", flag.ExitOnError)

// define command-line flags
inputPath := flag.String("input", "", "Path to the input image file")
outputPath := flag.String("output", "", "Path to save the compressed image")
maxSize := flag.Int("maxsize", 1048576, "Maximum file size in bytes (default 1MB)")
outputFormat := flag.String("format", "", "Output image format (jpeg, png, or gif)")
quality := flag.Int("quality", 85, "JPEG compression quality (1-100; 85 by default)")
verbose := flag.Bool("v", false, "Verbose logging enabled")
uploadGravatar := flag.Bool("upload-gravatar", false, "Upload compressed image to Gravatar")
inputPath := fs.String("input", "", "Path to the input image file")
outputPath := fs.String("output", "", "Path to save the compressed image")
maxSize := fs.Int("maxsize", 1048576, "Maximum file size in bytes (default 1MB)")
outputFormat := fs.String("format", "", "Output image format (jpeg, png, or gif)")
quality := fs.Int("quality", 85, "JPEG compression quality (1-100; 85 by default)")
verbose := fs.Bool("v", false, "Verbose logging enabled")
uploadGravatar := fs.Bool("upload-gravatar", false, "Upload compressed image to Gravatar")

// custom usage message for flags
flag.Usage = func() {
fs.Usage = func() {
fmt.Println("Usage: gitfit -input <input-image-file> -output <output-image-file> -maxsize <max size in bytes> " +
"-format <jpeg|png|gif> -quality <0-100> -v [for verbose logging] -upload-gravatar [to upload to Gravatar]")
fmt.Println("Example: gitfit -input input.jpeg -output output.jpeg -maxsize 1000000 -format jpeg -quality 85 -v -upload-gravatar")
fmt.Println("Flags:")
flag.PrintDefaults()
fs.PrintDefaults()
}

flag.Parse()
fs.Parse(args)

// Config struct populated with flag values
return &Config{
InputPath: *inputPath,
OutputPath: *outputPath,
Expand All @@ -87,7 +88,6 @@ func parseFlags() *Config {
func validateConfig(cfg *Config) (bool, error) {
// check if input and/or output path is missing
if cfg.InputPath == "" || cfg.OutputPath == "" {
// assume user knows about both flags if one is given
if cfg.InputPath == "" && cfg.OutputPath == "" {
return true, nil
}
Expand Down
Loading
Loading