Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
osv
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
Verlässliche Systemsoftware
projects
osv
Commits
cd308bc9
Commit
cd308bc9
authored
11 years ago
by
Guy Zana
Browse files
Options
Downloads
Patches
Plain Diff
cli: add command line parsing class util
parent
14a2b16c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bootfs.manifest
+1
-0
1 addition, 0 deletions
bootfs.manifest
console/cli.js
+1
-0
1 addition, 0 deletions
console/cli.js
console/optparse.js
+109
-0
109 additions, 0 deletions
console/optparse.js
with
111 additions
and
0 deletions
bootfs.manifest
+
1
−
0
View file @
cd308bc9
...
...
@@ -101,6 +101,7 @@
/usr/lib/&/jni/networking.so: java/&
/console/util.js: ../../console/util.js
/console/autocomplete.js: ../../console/autocomplete.js
/console/optparse.js: ../../console/optparse.js
/console/cd.js: ../../console/cd.js
/console/pwd.js: ../../console/pwd.js
/console/ls.js: ../../console/ls.js
...
...
This diff is collapsed.
Click to expand it.
console/cli.js
+
1
−
0
View file @
cd308bc9
...
...
@@ -3,6 +3,7 @@ importPackage(java.lang);
load
(
"
/console/util.js
"
);
load
(
"
/console/autocomplete.js
"
);
load
(
"
/console/optparse.js
"
);
load
(
"
/console/cd.js
"
);
load
(
"
/console/pwd.js
"
);
load
(
"
/console/ls.js
"
);
...
...
This diff is collapsed.
Click to expand it.
console/optparse.js
0 → 100644
+
109
−
0
View file @
cd308bc9
//
// Parsed options
//
// Description: being returned as an object created by the OptParser
//
function
ParsedOptions
()
{
}
ParsedOptions
.
prototype
.
_setTrue
=
function
(
attr
)
{
Object
.
defineProperty
(
this
,
attr
,
{
value
:
true
});
}
ParsedOptions
.
prototype
.
_setFalse
=
function
(
attr
)
{
Object
.
defineProperty
(
this
,
attr
,
{
value
:
false
});
}
ParsedOptions
.
prototype
.
_store
=
function
(
attr
,
a_value
)
{
Object
.
defineProperty
(
this
,
attr
,
{
value
:
a_value
});
}
//
// OptParser
//
// Description: parse command line out of metadata options
//
function
OptParser
(
options
)
{
this
.
options
=
options
;
this
.
names
=
new
Array
();
for
(
var
i
=
0
;
i
<
options
.
length
;
i
++
)
{
this
.
names
.
push
(
options
[
i
].
opt
);
}
}
OptParser
.
prototype
.
parse
=
function
(
commandline
)
{
var
parsed
=
new
ParsedOptions
();
// TODO: Search for unrecognized options and set "err"
// Parse options
for
(
var
i
=
0
;
i
<
this
.
options
.
length
;
i
++
)
{
var
opt
=
this
.
options
[
i
];
var
cmd_id
=
this
.
_findIdx
(
opt
.
opt
,
commandline
);
var
optname
=
opt
.
opt
;
// trim '-'
optname
=
optname
.
replace
(
/^-+/
,
""
);
if
(
cmd_id
==
-
1
)
{
parsed
.
_setFalse
(
optname
);
continue
;
}
if
(
opt
.
op
==
"
bool
"
)
{
parsed
.
_setTrue
(
optname
)
}
if
(
opt
.
op
==
"
store
"
)
{
if
((
cmd_id
+
1
>=
commandline
.
length
)
||
(
this
.
_isOption
(
commandline
[
cmd_id
+
1
])))
{
parsed
.
_store
(
"
err
"
,
"
option
"
+
opt
.
opt
+
"
must name a value
"
)
return
(
parsed
);
}
parsed
.
_store
(
optname
,
commandline
[
cmd_id
+
1
]);
}
}
return
(
parsed
);
}
OptParser
.
prototype
.
_isOption
=
function
(
arg
)
{
for
(
var
i
=
0
;
i
<
this
.
names
.
length
;
i
++
)
{
if
(
this
.
names
[
i
]
==
arg
)
{
return
(
true
);
}
}
return
(
false
);
}
// if val is found in arr, return the id, else return -1
OptParser
.
prototype
.
_findIdx
=
function
(
val
,
arr
)
{
for
(
var
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
if
(
arr
[
i
]
==
val
)
{
return
(
i
);
}
}
return
(
-
1
);
}
OptParser
.
prototype
.
printUsage
=
function
()
{
print
(
"
Options:
"
);
for
(
var
i
=
0
;
i
<
this
.
options
.
length
;
i
++
)
{
var
opt
=
this
.
options
[
i
];
var
out_opt
=
opt
.
opt
;
if
(
opt
.
op
==
"
store
"
)
{
if
(
opt
.
metaname
)
{
out_opt
+=
"
"
+
opt
.
metaname
;
}
else
{
out_opt
+=
"
<arg>
"
;
}
}
var
line
=
System
.
out
.
format
(
"
%-20s %s
\n
"
,
out_opt
,
opt
.
help
);
}
}
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