느슨한 엔지니어로 만들 수 있는 CLI 도구
Who?
트위터 : @carimatics
기분 좋게 엔지니어링이 가능한 환경을 만들고 싶다
라는 마음을 안고 조기성 서리
직장에서는 이렇게 잘 만져
- Shell script
- Perl
- 파이썬
- 자바스크립트
- AWS
- 도커
오늘의 이야기
CLI
만들기
CLI
Command Line Interface
행별로 명령을 실행하기 위한 도구입니다(잡)
좀 더 혼란스럽게 말하면 macOS terminal 또는 Windows cmd입니다.
왜 CLI 도구를 만드는거야?
shell script 쓰고 싶지 않은 것이 임계점을 넘어 폭발했다
파이썬이라도 좋았지만 아무 것도 도전이기 때문에 ...
사용할 라이브러리
urfave/cli
CLI
만들기
CLI
Command Line Interface
행별로 명령을 실행하기 위한 도구입니다(잡)
좀 더 혼란스럽게 말하면 macOS terminal 또는 Windows cmd입니다.
왜 CLI 도구를 만드는거야?
shell script 쓰고 싶지 않은 것이 임계점을 넘어 폭발했다
파이썬이라도 좋았지만 아무 것도 도전이기 때문에 ...
사용할 라이브러리
urfave/cli
CLI
Command Line Interface
행별로 명령을 실행하기 위한 도구입니다(잡)
좀 더 혼란스럽게 말하면 macOS terminal 또는 Windows cmd입니다.
왜 CLI 도구를 만드는거야?
shell script 쓰고 싶지 않은 것이 임계점을 넘어 폭발했다
파이썬이라도 좋았지만 아무 것도 도전이기 때문에 ...
사용할 라이브러리
urfave/cli
urfave/cli
flag (옵션)의 퍼스를 간단하게 할 수 있다 subcommands 만들기 쉽다git 명령의 add 라든지 commit 라든지 Usage를 기술하면 좋은 느낌의 도움말도 만들어 주기 때문에 매뉴얼이 썩기 어렵다 간단한 명령 만들기
모두 사랑
카운터!
동작은 이런 느낌(잡)

디렉토리 구성
mycmd
├── Gopkg.lock # 依存関係
├── Gopkg.toml # プロジェクトの設定
├── count.txt # ストレージ(雑)
├── main.go # entry point
├── modules # 今回作ったコマンド処理本体
│ └── commands
│ └── counter
│ └── counter_command.go
└── vendor # 外部ライブラリ
└── github.com
└── urfave
└── cli
할 일
이것만!
카운터!
동작은 이런 느낌(잡)

디렉토리 구성
mycmd
├── Gopkg.lock # 依存関係
├── Gopkg.toml # プロジェクトの設定
├── count.txt # ストレージ(雑)
├── main.go # entry point
├── modules # 今回作ったコマンド処理本体
│ └── commands
│ └── counter
│ └── counter_command.go
└── vendor # 外部ライブラリ
└── github.com
└── urfave
└── cli
할 일
이것만!

디렉토리 구성
mycmd
├── Gopkg.lock # 依存関係
├── Gopkg.toml # プロジェクトの設定
├── count.txt # ストレージ(雑)
├── main.go # entry point
├── modules # 今回作ったコマンド処理本体
│ └── commands
│ └── counter
│ └── counter_command.go
└── vendor # 外部ライブラリ
└── github.com
└── urfave
└── cli
할 일
이것만!
mycmd
├── Gopkg.lock # 依存関係
├── Gopkg.toml # プロジェクトの設定
├── count.txt # ストレージ(雑)
├── main.go # entry point
├── modules # 今回作ったコマンド処理本体
│ └── commands
│ └── counter
│ └── counter_command.go
└── vendor # 外部ライブラリ
└── github.com
└── urfave
└── cli
이것만!
애플리케이션 설정
app := cli.NewApp()
app.Name = "mycmd"
app.Usage = "The sample application"
app.Version = "0.0.1"
Command 등록
이번에는 counter 명령 추가
app.Commands = []cli.Command{
counter.CounterCommand(count),
}
명령을 치면 다음과 같이 표시됩니다.
$ mycmd
NAME:
mycmd - The sample application
USAGE:
mycmd [global options] command [command options] [arguments...]
VERSION:
0.0.1
COMMANDS:
counter Execute count up/down
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
Action 등록
CounterCommand
cli.Command{
Name: "counter",
Usage: "Execute count up/down",
Action: func(context *cli.Context) error {
printCurrentCount(count)
return nil
},
Subcommands: []cli.Command{
upCommand(count),
downCommand(count),
},
}
명령을 두드리면
$ mycnt counter
current count: 0
SubCommand 등록
다운
cli.Command{
Name: "down",
Usage: "Down count",
Action: func(context *cli.Context) error {
count--
printCurrentCount(count)
saveCount(count)
return nil
},
}
명령을 두드리면
$ mycnt counter
current count: -1
요약
CLI 도구 쉽게 만들 수 있습니다 ~!
모두가 더 유익한 명령을 만들자!
Reference
이 문제에 관하여(느슨한 엔지니어로 만들 수 있는 CLI 도구), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/carimatics/items/7a345aa2429ca0bf5663
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
app := cli.NewApp()
app.Name = "mycmd"
app.Usage = "The sample application"
app.Version = "0.0.1"
이번에는 counter 명령 추가
app.Commands = []cli.Command{
counter.CounterCommand(count),
}
명령을 치면 다음과 같이 표시됩니다.
$ mycmd
NAME:
mycmd - The sample application
USAGE:
mycmd [global options] command [command options] [arguments...]
VERSION:
0.0.1
COMMANDS:
counter Execute count up/down
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
Action 등록
CounterCommand
cli.Command{
Name: "counter",
Usage: "Execute count up/down",
Action: func(context *cli.Context) error {
printCurrentCount(count)
return nil
},
Subcommands: []cli.Command{
upCommand(count),
downCommand(count),
},
}
명령을 두드리면
$ mycnt counter
current count: 0
SubCommand 등록
다운
cli.Command{
Name: "down",
Usage: "Down count",
Action: func(context *cli.Context) error {
count--
printCurrentCount(count)
saveCount(count)
return nil
},
}
명령을 두드리면
$ mycnt counter
current count: -1
요약
CLI 도구 쉽게 만들 수 있습니다 ~!
모두가 더 유익한 명령을 만들자!
Reference
이 문제에 관하여(느슨한 엔지니어로 만들 수 있는 CLI 도구), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/carimatics/items/7a345aa2429ca0bf5663
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
$ mycmd
NAME:
mycmd - The sample application
USAGE:
mycmd [global options] command [command options] [arguments...]
VERSION:
0.0.1
COMMANDS:
counter Execute count up/down
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
CounterCommand
cli.Command{
Name: "counter",
Usage: "Execute count up/down",
Action: func(context *cli.Context) error {
printCurrentCount(count)
return nil
},
Subcommands: []cli.Command{
upCommand(count),
downCommand(count),
},
}
명령을 두드리면
$ mycnt counter
current count: 0
SubCommand 등록
다운
cli.Command{
Name: "down",
Usage: "Down count",
Action: func(context *cli.Context) error {
count--
printCurrentCount(count)
saveCount(count)
return nil
},
}
명령을 두드리면
$ mycnt counter
current count: -1
요약
CLI 도구 쉽게 만들 수 있습니다 ~!
모두가 더 유익한 명령을 만들자!
Reference
이 문제에 관하여(느슨한 엔지니어로 만들 수 있는 CLI 도구), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/carimatics/items/7a345aa2429ca0bf5663
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
cli.Command{
Name: "down",
Usage: "Down count",
Action: func(context *cli.Context) error {
count--
printCurrentCount(count)
saveCount(count)
return nil
},
}
$ mycnt counter
current count: -1
CLI 도구 쉽게 만들 수 있습니다 ~!
모두가 더 유익한 명령을 만들자!
Reference
이 문제에 관하여(느슨한 엔지니어로 만들 수 있는 CLI 도구), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/carimatics/items/7a345aa2429ca0bf5663텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)