Skip to content
This repository was archived by the owner on Jul 3, 2023. It is now read-only.

Commit 661ff5d

Browse files
committed
items create, items update の --file, --write フラグを廃止
1 parent 6967d58 commit 661ff5d

File tree

4 files changed

+10
-117
lines changed

4 files changed

+10
-117
lines changed

cmd/qiita/flags.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,6 @@ var (
6565

6666
// items create
6767
var (
68-
// --file
69-
flagItemsCreateFile = &flags.String{Flag: &flags.Flag{
70-
Name: "file",
71-
Description: "create an item from a file",
72-
}}
73-
74-
// --write
75-
flagItemsCreateWrite = &flags.Bool{Flag: &flags.Flag{
76-
Name: "write",
77-
Description: "write information about the created item to a file",
78-
}}
79-
8068
// --title
8169
flagItemsCreateTitle = &flags.String{Flag: &flags.Flag{
8270
Name: "title",
@@ -110,18 +98,6 @@ var (
11098

11199
// items update
112100
var (
113-
// --file
114-
flagItemsUpdateFile = &flags.String{Flag: &flags.Flag{
115-
Name: "file",
116-
Description: "update an item from a file",
117-
}}
118-
119-
// --write
120-
flagItemsUpdateWrite = &flags.Bool{Flag: &flags.Flag{
121-
Name: "write",
122-
Description: "write information about the updated item to a file",
123-
}}
124-
125101
// --title
126102
flagItemsUpdateTitle = &flags.String{Flag: &flags.Flag{
127103
Name: "title",

cmd/qiita/items.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ var itemsCreateCmd = &cobra.Command{
9090
}
9191

9292
if err := c.ItemsCreate(&cli.ItemsCreateParameters{
93-
FlagFile: flagItemsCreateFile, // --file
94-
FlagWrite: flagItemsCreateWrite, // --write
9593
FlagTitle: flagItemsCreateTitle, // --title
9694
FlagBody: flagItemsCreateBody, // --body
9795
FlagTags: flagItemsCreateTags, // --tags
@@ -118,8 +116,6 @@ var itemsUpdateCmd = &cobra.Command{
118116

119117
if err := c.ItemsUpdate(&cli.ItemsUpdateParameters{
120118
Args: args,
121-
FlagFile: flagItemsUpdateFile, // --file
122-
FlagWrite: flagItemsUpdateWrite, // --write
123119
FlagTitle: flagItemsUpdateTitle, // --title
124120
FlagTags: flagItemsUpdateTags, // --tags
125121
FlagBody: flagItemsUpdateBody, // --body

cmd/qiita/root.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ func init() {
9797
flags.Flags{
9898
flagFormat, // --format
9999
flagItemsColumns, // --columns
100-
flagItemsCreateFile, // --file
101-
flagItemsCreateWrite, // --write
102100
flagItemsCreateTitle, // --title
103101
flagItemsCreateTags, // --tags
104102
flagItemsCreateBody, // --body
@@ -110,8 +108,6 @@ func init() {
110108
flags.Flags{
111109
flagFormat, // --format
112110
flagItemsColumns, // --columns
113-
flagItemsUpdateFile, // --file
114-
flagItemsUpdateWrite, // --write
115111
flagItemsUpdateTitle, // --title
116112
flagItemsUpdateTags, // --tags
117113
flagItemsUpdateBody, // --body

internal/cli/items.go

Lines changed: 10 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ func (c *CLI) ItemsGet(params *ItemsGetParameters) error {
7979
}
8080

8181
type ItemsCreateParameters struct {
82-
FlagFile *flags.String // --file
83-
FlagWrite *flags.Bool // --write
8482
FlagTitle *flags.String // --title
8583
FlagTags *flags.StringSlice // --tags
8684
FlagBody *flags.String // --body
@@ -90,54 +88,21 @@ type ItemsCreateParameters struct {
9088

9189
// $ qiita items create
9290
func (c *CLI) ItemsCreate(params *ItemsCreateParameters) error {
93-
if params.FlagWrite.Changed(c.command) && !params.FlagFile.Changed(c.command) {
94-
return ErrWriteWithoutFile
95-
}
96-
file := params.FlagFile.Get(c.command, false)
97-
98-
p := &qiita.CreateItemParameters{}
99-
100-
if file != nil {
101-
md, fm, err := c.readMarkdown(*file)
102-
if err != nil {
103-
return err
104-
}
105-
if fm.ID != nil {
106-
return ErrCreateWithID
107-
}
108-
p.Title = fm.Title
109-
p.Tags = fm.QiitaTags()
110-
p.Body = &md
111-
p.Private = fm.Private
112-
}
113-
114-
if params.FlagTitle.Changed(c.command) {
115-
p.Title = params.FlagTitle.Get(c.command, true)
91+
p := &qiita.CreateItemParameters{
92+
Title: params.FlagTitle.Get(c.command, false),
93+
Body: params.FlagBody.Get(c.command, false),
94+
Private: params.FlagPrivate.Get(c.command, false),
95+
Tweet: params.FlagTweet.Get(c.command, false),
11696
}
11797
if params.FlagTags.Changed(c.command) {
11898
p.Tags = util.Ptr(qiita.TagsFromStrings(*params.FlagTags.Get(c.command, true)))
11999
}
120-
if params.FlagBody.Changed(c.command) {
121-
p.Body = params.FlagBody.Get(c.command, true)
122-
}
123-
if params.FlagPrivate.Changed(c.command) {
124-
p.Private = params.FlagPrivate.Get(c.command, true)
125-
}
126-
if params.FlagTweet.Changed(c.command) {
127-
p.Tweet = params.FlagTweet.Get(c.command, true)
128-
}
129100

130101
item, err := c.client.CreateItem(p)
131102
if err != nil {
132103
return err
133104
}
134105

135-
if *params.FlagWrite.Get(c.command, true) {
136-
if err := c.writeMarkdown(*file, item); err != nil {
137-
return err
138-
}
139-
}
140-
141106
if err := c.printer.Print(c.writer, item); err != nil {
142107
return err
143108
}
@@ -147,68 +112,28 @@ func (c *CLI) ItemsCreate(params *ItemsCreateParameters) error {
147112

148113
type ItemsUpdateParameters struct {
149114
Args []string
150-
FlagFile *flags.String // --file
151-
FlagWrite *flags.Bool // --write
152115
FlagTitle *flags.String // --title
153116
FlagTags *flags.StringSlice // --tags
154117
FlagBody *flags.String // --body
155118
FlagPrivate *flags.Bool // --private
156119
}
157120

158121
func (c *CLI) ItemsUpdate(params *ItemsUpdateParameters) error {
159-
if params.FlagWrite.Changed(c.command) && !params.FlagFile.Changed(c.command) {
160-
return ErrWriteWithoutFile
161-
}
162-
file := params.FlagFile.Get(c.command, false)
163-
164-
var id string
165-
p := &qiita.UpdateItemParameters{}
166-
167-
if file != nil {
168-
md, fm, err := c.readMarkdown(*file)
169-
if err != nil {
170-
return err
171-
}
172-
if fm.ID != nil {
173-
id = *fm.ID
174-
}
175-
p.Title = fm.Title
176-
p.Tags = fm.QiitaTags()
177-
p.Body = &md
178-
p.Private = fm.Private
179-
}
180-
181-
if len(params.Args) > 0 {
182-
id = params.Args[0]
183-
}
184-
if id == "" {
185-
return ErrIDRequired
186-
}
187-
188-
if params.FlagTitle.Changed(c.command) {
189-
p.Title = params.FlagTitle.Get(c.command, true)
122+
id := params.Args[0]
123+
p := &qiita.UpdateItemParameters{
124+
Title: params.FlagTitle.Get(c.command, false),
125+
Body: params.FlagBody.Get(c.command, false),
126+
Private: params.FlagPrivate.Get(c.command, false),
190127
}
191128
if params.FlagTags.Changed(c.command) {
192129
p.Tags = util.Ptr(qiita.TagsFromStrings(*params.FlagTags.Get(c.command, true)))
193130
}
194-
if params.FlagBody.Changed(c.command) {
195-
p.Body = params.FlagBody.Get(c.command, true)
196-
}
197-
if params.FlagPrivate.Changed(c.command) {
198-
p.Private = params.FlagPrivate.Get(c.command, true)
199-
}
200131

201132
item, err := c.client.UpdateItem(id, p)
202133
if err != nil {
203134
return err
204135
}
205136

206-
if *params.FlagWrite.Get(c.command, true) {
207-
if err := c.writeMarkdown(*file, item); err != nil {
208-
return err
209-
}
210-
}
211-
212137
if err := c.printer.Print(c.writer, item); err != nil {
213138
return err
214139
}

0 commit comments

Comments
 (0)