Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
status
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ai
status
Commits
18f4a712
Commit
18f4a712
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
invoke an editor if no message is given on the command line
parent
e7e48ad1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/status/status.go
+41
-6
41 additions, 6 deletions
cmd/status/status.go
with
41 additions
and
6 deletions
cmd/status/status.go
+
41
−
6
View file @
18f4a712
...
...
@@ -4,10 +4,12 @@ import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
"os/exec"
"strings"
"git.autistici.org/ai/status"
...
...
@@ -24,17 +26,45 @@ var (
doList
=
flag
.
Bool
(
"list"
,
false
,
"list all open events"
)
)
func
getMessage
()
string
{
// The update message can be passed as command-line arguments.
msg
:=
strings
.
Join
(
flag
.
Args
(),
" "
)
// Otherwise, invoke $EDITOR on a temporary file.
if
msg
==
""
{
tmpf
,
err
:=
ioutil
.
TempFile
(
""
,
"update-"
)
if
err
!=
nil
{
log
.
Fatalf
(
"Could not create temporary file: %v"
,
err
)
}
tmpf
.
Close
()
defer
os
.
Remove
(
tmpf
.
Name
())
editor
:=
os
.
Getenv
(
"EDITOR"
)
if
editor
==
""
{
editor
=
"/usr/bin/vi"
}
log
.
Printf
(
"running %s %s"
,
editor
,
tmpf
.
Name
())
cmd
:=
exec
.
Command
(
editor
,
tmpf
.
Name
())
cmd
.
Stdin
=
os
.
Stdin
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
if
err
:=
cmd
.
Run
();
err
!=
nil
{
log
.
Fatalf
(
"Update aborted: %v"
,
err
)
}
msgBytes
,
err
:=
ioutil
.
ReadFile
(
tmpf
.
Name
())
if
err
!=
nil
{
log
.
Fatalf
(
"Could not re-read update message: %v"
,
err
)
}
msg
=
string
(
msgBytes
)
}
return
msg
}
func
main
()
{
flag
.
Parse
()
// The message is just passed as command-line arguments.
msg
:=
strings
.
Join
(
flag
.
Args
(),
" "
)
// Check for conflicting options.
if
!*
doList
{
if
msg
==
""
{
log
.
Fatal
(
"No message provided"
)
}
if
*
isNew
{
if
*
doClose
{
log
.
Fatal
(
"--new and --close can not be specified together"
)
...
...
@@ -42,6 +72,9 @@ func main() {
if
*
eventId
!=
""
{
log
.
Fatal
(
"--new and --id can not be specified together"
)
}
if
*
title
==
""
{
log
.
Fatal
(
"New issues must have a title (use the --title option)"
)
}
}
if
!*
isNew
&&
*
eventId
==
""
{
log
.
Fatal
(
"You need to provide at least one of --new (to create a new event) or --id (to update an existing one)"
)
...
...
@@ -83,6 +116,8 @@ func main() {
return
}
msg
:=
getMessage
()
var
path
string
v
:=
make
(
url
.
Values
)
v
.
Set
(
"author"
,
*
user
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment