Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bulletin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Personal Projects
bulletin
Commits
923b0c03
Unverified
Commit
923b0c03
authored
2 months ago
by
Kevin Lyda
Browse files
Options
Downloads
Patches
Plain Diff
Initial pass at command parser
parent
923b15ab
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
dclish/dclish.go
+49
-0
49 additions, 0 deletions
dclish/dclish.go
repl/command.go
+2512
-263
2512 additions, 263 deletions
repl/command.go
repl/repl.go
+4
-6
4 additions, 6 deletions
repl/repl.go
with
2565 additions
and
269 deletions
dclish/dclish.go
0 → 100644
+
49
−
0
View file @
923b0c03
// Package dclish A DCL-like command line parser.
package
dclish
import
(
"fmt"
"strings"
)
// ActionFunc is the function that a command runs.
type
ActionFunc
func
(
string
,
*
Command
)
error
// Flag is a flag for a command.
type
Flag
struct
{
Name
string
Value
string
Description
string
}
// Flags is the list of flags.
type
Flags
[]
*
Flag
// Command contains the definition of a command, it's flags and subcommands.
type
Command
struct
{
Command
string
Flags
Flags
Args
[]
string
Commands
[]
*
Command
Action
ActionFunc
Description
string
}
// Commands is the full list of commands.
type
Commands
[]
*
Command
// ParseAndRun parses a command line and runs the command.
func
(
c
Commands
)
ParseAndRun
(
line
string
)
error
{
// TODO: this doesn't handle a DCL command line completely.
words
:=
strings
.
Fields
(
line
)
fmt
.
Printf
(
"TODO ParseAndRun sees: %s
\n
"
,
words
)
cmd
:=
strings
.
ToUpper
(
words
[
0
])
for
i
:=
range
c
{
if
c
[
i
]
.
Command
==
cmd
{
fmt
.
Printf
(
"Command help:
\n
%s
\n
"
,
c
[
i
]
.
Description
)
return
nil
}
}
fmt
.
Printf
(
"ERROR: Unknown command '%s'
\n
"
,
cmd
)
return
nil
}
This diff is collapsed.
Click to expand it.
repl/command.go
+
2512
−
263
View file @
923b0c03
This diff is collapsed.
Click to expand it.
repl/repl.go
+
4
−
6
View file @
923b0c03
...
@@ -3,7 +3,6 @@ package repl
...
@@ -3,7 +3,6 @@ package repl
import
(
import
(
"fmt"
"fmt"
"strings"
"github.com/chzyer/readline"
"github.com/chzyer/readline"
)
)
...
@@ -22,13 +21,12 @@ func Loop(user string) error {
...
@@ -22,13 +21,12 @@ func Loop(user string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
words
:=
strings
.
Field
(
strings
.
ReplaceAll
(
line
,
"/"
,
" /"
))
if
len
(
line
)
==
0
{
if
len
(
words
)
{
continue
continue
}
}
switch
strings
.
ToUpper
(
words
[
0
])
{
err
=
commands
.
ParseAndRun
(
line
)
case
"ADD"
:
if
err
!=
nil
{
commandAdd
()
return
err
}
}
}
}
...
...
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