$ goapp run main.go -path ~/git/material-design-icons/ -name=ic_attach_file_black_18dp -cat editor
path: /Users/keima/git/material-design-icons/
category: editor
name: ic_attach_file_black_18dp
/Users/keima/git/material-design-icons//editor/drawable-hdpi/ic_attach_file_black_18dp.png
Start: copy sequence
> Copy Success: ./output//drawable-hdpi/ic_attach_file_black_18dp.png
> Copy Success: ./output//drawable-mdpi/ic_attach_file_black_18dp.png
> Copy Success: ./output//drawable-xhdpi/ic_attach_file_black_18dp.png
> Copy Success: ./output//drawable-xxhdpi/ic_attach_file_black_18dp.png
> Copy Success: ./output//drawable-xxxhdpi/ic_attach_file_black_18dp.png
Finish: copy sequence
$ goapp run main.go -path ~/git/material-design-icons/ -name=ic_merge_type_file_black_18dp -cat editor
path: /Users/keima/git/material-design-icons/
category: editor
name: ic_merge_type_file_black_18dp
/Users/keima/git/material-design-icons//editor/drawable-hdpi/ic_merge_type_file_black_18dp.png
file is not found
exit status 1
$ goapp run main.go -path ~/git/material-design-icons/ -name=ic_merge_type_black_18dp -cat editor
path: /Users/keima/git/material-design-icons/
category: editor
name: ic_merge_type_black_18dp
/Users/keima/git/material-design-icons//editor/drawable-hdpi/ic_merge_type_black_18dp.png
Start: copy sequence
> Copy Success: ./output//drawable-hdpi/ic_merge_type_black_18dp.png
> Copy Success: ./output//drawable-mdpi/ic_merge_type_black_18dp.png
> Copy Success: ./output//drawable-xhdpi/ic_merge_type_black_18dp.png
> Copy Success: ./output//drawable-xxhdpi/ic_merge_type_black_18dp.png
> Copy Success: ./output//drawable-xxxhdpi/ic_merge_type_black_18dp.png
Finish: copy sequence
$ tree output/
output/
├── drawable-hdpi
│ ├── ic_attach_file_black_18dp.png
│ └── ic_merge_type_black_18dp.png
├── drawable-mdpi
│ ├── ic_attach_file_black_18dp.png
│ └── ic_merge_type_black_18dp.png
├── drawable-xhdpi
│ ├── ic_attach_file_black_18dp.png
│ └── ic_merge_type_black_18dp.png
├── drawable-xxhdpi
│ ├── ic_attach_file_black_18dp.png
│ └── ic_merge_type_black_18dp.png
└── drawable-xxxhdpi
├── ic_attach_file_black_18dp.png
└── ic_merge_type_black_18dp.png
5 directories, 10 files
Last active
August 29, 2015 14:08
-
-
Save keima/9ddd93d454ac40ecb26a to your computer and use it in GitHub Desktop.
google/material_design_icons choose helper script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"errors" | |
"flag" | |
"fmt" | |
"io/ioutil" | |
"os" | |
) | |
var ( | |
CATEGORY = []string{ | |
"action", | |
"alert", | |
"av", | |
"communication", | |
"content", | |
"device", | |
"editor", | |
"file", | |
"hardware", | |
"image", | |
"maps", | |
"navigation", | |
"notification", | |
"social", | |
"toggle", | |
} | |
VARIATION = []string{ | |
// Currently, available only Android | |
// "1x_ios", | |
// "1x_web", | |
// "2x_ios", | |
// "2x_web", | |
// "3x_ios", | |
"drawable-hdpi", | |
"drawable-mdpi", | |
"drawable-xhdpi", | |
"drawable-xxhdpi", | |
"drawable-xxxhdpi", | |
// "svg", | |
} | |
) | |
func main() { | |
path := flag.String("path", "", "google/material-design-icons path") | |
category := flag.String("cat", "", "category name (e.g.: content )") | |
name := flag.String("name", "", "icon name (e.g.: ic_send_white_24dp )") | |
flag.Parse() | |
fmt.Println("path: ", *path) | |
fmt.Println("category: ", *category) | |
fmt.Println("name: ", *name) | |
if *path == "" { | |
fmt.Println("Path is not found!") | |
os.Exit(1) | |
} | |
if *category == "" { | |
fmt.Println("Category is not found!") | |
os.Exit(1) | |
} | |
if *name == "" { | |
fmt.Println("Name is not found!") | |
os.Exit(1) | |
} | |
if err := existFile(*name, *category, *path); err != nil { | |
fmt.Println(err.Error()) | |
os.Exit(1) | |
} | |
copyFiles(*name, *category, *path, "./output/") | |
os.Exit(0) | |
} | |
func existFile(fileName string, category string, dir string) error { | |
if _, err := os.Stat(dir); err != nil { | |
return errors.New("dir is not found") | |
} | |
for index, cat := range CATEGORY { | |
if category == cat { | |
break | |
} | |
if index == len(CATEGORY)-1 { | |
return errors.New("category name is invalid") | |
} | |
} | |
// とりあえずてきとーに | |
fileFullPath := dir + "/" + category + "/" + VARIATION[0] + "/" + fileName + ".png" | |
fmt.Println(fileFullPath) | |
if _, err := os.Stat(fileFullPath); err != nil { | |
return errors.New("file is not found") | |
} | |
return nil | |
} | |
func copyFiles(fileName string, category string, srcDir string, dstDir string) { | |
fmt.Println("Start: copy sequence") | |
fileNameExt := fileName + ".png" | |
for _, variation := range VARIATION { | |
srcDirFullPath := srcDir + "/" + category + "/" + variation + "/" | |
dstDirFullPath := dstDir + "/" + variation + "/" | |
srcFullPath := srcDirFullPath + fileNameExt | |
dstFullPath := dstDirFullPath + fileNameExt | |
// fmt.Println("src: ", srcFullPath) | |
// fmt.Println("dst: ", dstFullPath) | |
if err := os.MkdirAll(dstDirFullPath, 0777); err != nil { | |
panic(err) | |
} | |
b, err := ioutil.ReadFile(srcFullPath) | |
if err != nil { | |
panic(err) | |
} | |
err = ioutil.WriteFile(dstFullPath, b, 0644) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("> Copy Success: " + dstFullPath) | |
} | |
fmt.Println("Finish: copy sequence") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment