Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Adora Belle Go Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philip Kaluđerčić
Adora Belle Go Library
Commits
c7005860
Commit
c7005860
authored
4 years ago
by
Philip Kaluđerčić
Committed by
Philip Kaluđerčić
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
added abcli
parent
58d7bad2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+2
-0
2 additions, 0 deletions
README.md
cmd/abcli/cli.go
+104
-0
104 additions, 0 deletions
cmd/abcli/cli.go
cmd/abcli/main.go
+45
-0
45 additions, 0 deletions
cmd/abcli/main.go
with
151 additions
and
0 deletions
README.md
+
2
−
0
View file @
c7005860
...
@@ -8,6 +8,7 @@ This repository contains a number of client under the `cmd` directory.
...
@@ -8,6 +8,7 @@ This repository contains a number of client under the `cmd` directory.
Currently, these are:
Currently, these are:
-
**abhelp**
: Request help
-
**abhelp**
: Request help
-
**abcli**
: Handle requests in a queue
Meta
Meta
----
----
...
@@ -20,3 +21,4 @@ the FAU CS [GitLab][gitlab].
...
@@ -20,3 +21,4 @@ the FAU CS [GitLab][gitlab].
[
ab
]:
https://github.com/noctux/adora-belle
[
ab
]:
https://github.com/noctux/adora-belle
[
go
]:
https://golang.org/
[
go
]:
https://golang.org/
[
license
]:
./LICENSE
[
license
]:
./LICENSE
[
gitlab
]:
https://gitlab.cs.fau.de/oj14ozun/ablib
This diff is collapsed.
Click to expand it.
cmd/abcli/cli.go
0 → 100644
+
104
−
0
View file @
c7005860
package
main
import
(
"ablib"
"fmt"
"os"
"sync"
"golang.org/x/crypto/ssh/terminal"
)
type
cmd
struct
{
cmd
ablib
.
Command
data
string
arg
string
}
type
cli
struct
{
sync
.
Mutex
u
string
q
[]
*
ablib
.
Request
c
chan
*
cmd
}
func
(
c
*
cli
)
interaction
()
{
var
(
r
*
ablib
.
Request
char
byte
verb
string
)
old
,
err
:=
terminal
.
MakeRaw
(
0
)
if
err
!=
nil
{
panic
(
err
)
}
for
{
fmt
.
Scanf
(
"%c"
,
&
char
)
switch
char
{
case
'q'
,
0x3
:
c
.
Lock
()
terminal
.
Restore
(
0
,
old
)
os
.
Exit
(
0
)
case
'd'
,
' '
:
verb
=
"Discard"
case
'h'
,
'\r'
:
verb
=
"Handle"
}
c
.
Lock
()
r
=
c
.
q
[
0
]
c
.
q
=
c
.
q
[
1
:
]
c
.
Unlock
()
c
.
c
<-
&
cmd
{
ablib
.
Handle
,
r
.
ID
,
verb
}
}
}
func
(
c
*
cli
)
HandleError
(
err
error
)
{
fmt
.
Fprintf
(
os
.
Stderr
,
"ERROR: %s"
,
err
)
}
func
(
c
*
cli
)
OnRequest
(
r
*
ablib
.
Request
,
handled
string
)
{
if
handled
!=
""
{
return
}
c
.
Lock
()
defer
c
.
Unlock
()
c
.
q
=
append
(
c
.
q
,
r
)
fmt
.
Printf
(
"% 4d: new
\"
%s
\"
request by %s (%s)
\n
"
,
len
(
c
.
q
),
r
.
Type
,
r
.
User
,
r
.
ID
)
}
func
(
c
*
cli
)
OnAction
(
a
*
ablib
.
Action
)
{
// remove request from queue
c
.
Lock
()
defer
c
.
Unlock
()
k
:=
-
1
for
i
,
r
:=
range
c
.
q
{
if
r
==
a
.
Request
{
k
=
i
break
}
}
if
k
!=
-
1
{
// from https://github.com/golang/go/wiki/SliceTricks
copy
(
c
.
q
[
k
:
],
c
.
q
[
k
+
1
:
])
c
.
q
[
len
(
c
.
q
)
-
1
]
=
nil
c
.
q
=
c
.
q
[
:
len
(
c
.
q
)
-
1
]
}
if
a
.
Name
==
c
.
u
{
fmt
.
Printf
(
"% 4d: handling %s: %s
\n
"
,
len
(
c
.
q
),
a
.
Request
.
ID
,
a
.
Request
.
Room
)
}
else
{
fmt
.
Printf
(
"% 4d: request %s handled by %s
\n
"
,
len
(
c
.
q
),
a
.
Request
.
ID
,
a
.
Name
)
}
}
func
(
c
*
cli
)
Listen
()
(
ablib
.
Command
,
string
,
string
,
error
)
{
cmd
:=
<-
c
.
c
return
cmd
.
cmd
,
cmd
.
data
,
cmd
.
arg
,
nil
}
This diff is collapsed.
Click to expand it.
cmd/abcli/main.go
0 → 100644
+
45
−
0
View file @
c7005860
package
main
import
(
"ablib"
"flag"
"fmt"
"os"
"time"
)
const
usage
=
"Usage: %s [options] [help|serve|request]"
func
main
()
{
var
(
interval
uint
user
,
pass
,
class
string
)
// parse flags
flag
.
UintVar
(
&
interval
,
"interval"
,
10
,
"interval in seconds between re-query"
)
flag
.
StringVar
(
&
class
,
"class"
,
os
.
Getenv
(
"AB_CLASS"
),
"name of class"
)
flag
.
StringVar
(
&
user
,
"user"
,
os
.
Getenv
(
"AB_USER"
),
""
)
flag
.
StringVar
(
&
pass
,
"pass"
,
os
.
Getenv
(
"AB_PASS"
),
""
)
flag
.
Parse
()
// set up api
api
:=
ablib
.
API
{
Interval
:
time
.
Duration
(
interval
)
*
time
.
Second
,
User
:
user
,
Pass
:
pass
,
}
if
!
api
.
SetupClass
(
class
)
{
fmt
.
Fprintln
(
os
.
Stderr
,
"Unknown class name
\"
%s
\"
"
,
class
)
os
.
Exit
(
1
)
}
// start ui loop
ui
:=
&
cli
{
u
:
user
,
c
:
make
(
chan
*
cmd
)}
go
ui
.
interaction
()
if
err
:=
api
.
Run
(
ui
);
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
os
.
Exit
(
1
)
}
}
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