Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
55d133ea
Commit
55d133ea
authored
Apr 12, 2015
by
Eric Paris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
doc/bash completions autogeneration directory helper
parent
ebb0affc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
104 additions
and
56 deletions
+104
-56
gen_kubectl_bash_comp.go
cmd/genbashcomp/gen_kubectl_bash_comp.go
+6
-17
gen_kubectl_docs.go
cmd/gendocs/gen_kubectl_docs.go
+8
-20
gen_kubectl_man.go
cmd/genman/gen_kubectl_man.go
+7
-19
genutils.go
cmd/genutils/genutils.go
+41
-0
genutils_test.go
cmd/genutils/genutils_test.go
+42
-0
No files found.
cmd/genbashcomp/gen_kubectl_bash_comp.go
View file @
55d133ea
...
@@ -20,39 +20,28 @@ import (
...
@@ -20,39 +20,28 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path/filepath"
"github.com/GoogleCloudPlatform/kubernetes/cmd/genutils"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
)
)
func
main
()
{
func
main
()
{
// use os.Args instead of "flags" because "flags" will mess up the man pages!
// use os.Args instead of "flags" because "flags" will mess up the man pages!
outDir
:=
"contrib/completions/bash/"
path
:=
"contrib/completions/bash/"
if
len
(
os
.
Args
)
==
2
{
if
len
(
os
.
Args
)
==
2
{
outDir
=
os
.
Args
[
1
]
path
=
os
.
Args
[
1
]
}
else
if
len
(
os
.
Args
)
>
2
{
}
else
if
len
(
os
.
Args
)
>
2
{
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s [output directory]
\n
"
,
os
.
Args
[
0
])
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s [output directory]
\n
"
,
os
.
Args
[
0
])
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
outDir
,
err
:=
filepath
.
Abs
(
outDir
)
outDir
,
err
:=
genutils
.
OutDir
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
err
.
Error
()
)
fmt
.
Fprintf
(
os
.
Stderr
,
"failed to get output directory: %v
\n
"
,
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
outFile
:=
outDir
+
"kubectl"
stat
,
err
:=
os
.
Stat
(
outDir
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"output directory %s does not exist
\n
"
,
outDir
)
os
.
Exit
(
1
)
}
if
!
stat
.
IsDir
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"output directory %s is not a directory
\n
"
,
outDir
)
os
.
Exit
(
1
)
}
outFile
:=
outDir
+
"/kubectl"
//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
kubectl
:=
cmd
.
NewKubectlCommand
(
cmdutil
.
NewFactory
(
nil
),
os
.
Stdin
,
ioutil
.
Discard
,
ioutil
.
Discard
)
kubectl
:=
cmd
.
NewKubectlCommand
(
cmdutil
.
NewFactory
(
nil
),
os
.
Stdin
,
ioutil
.
Discard
,
ioutil
.
Discard
)
...
...
cmd/gendocs/gen_kubectl_docs.go
View file @
55d133ea
...
@@ -20,8 +20,8 @@ import (
...
@@ -20,8 +20,8 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path/filepath"
"github.com/GoogleCloudPlatform/kubernetes/cmd/genutils"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/spf13/cobra"
"github.com/spf13/cobra"
...
@@ -29,36 +29,24 @@ import (
...
@@ -29,36 +29,24 @@ import (
func
main
()
{
func
main
()
{
// use os.Args instead of "flags" because "flags" will mess up the man pages!
// use os.Args instead of "flags" because "flags" will mess up the man pages!
docsDir
:=
"docs/man/man1
/"
path
:=
"docs
/"
if
len
(
os
.
Args
)
==
2
{
if
len
(
os
.
Args
)
==
2
{
docsDir
=
os
.
Args
[
1
]
path
=
os
.
Args
[
1
]
}
else
if
len
(
os
.
Args
)
>
2
{
}
else
if
len
(
os
.
Args
)
>
2
{
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s [output directory]
\n
"
,
os
.
Args
[
0
])
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s [output directory]
\n
"
,
os
.
Args
[
0
])
return
os
.
Exit
(
1
)
}
}
docsDir
,
err
:=
filepath
.
Abs
(
docsDir
)
outDir
,
err
:=
genutils
.
OutDir
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
err
.
Error
()
)
fmt
.
Fprintf
(
os
.
Stderr
,
"failed to get output directory: %v
\n
"
,
err
)
return
os
.
Exit
(
1
)
}
}
stat
,
err
:=
os
.
Stat
(
docsDir
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"output directory %s does not exist
\n
"
,
docsDir
)
return
}
if
!
stat
.
IsDir
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"output directory %s is not a directory
\n
"
,
docsDir
)
return
}
docsDir
=
docsDir
+
"/"
// Set environment variables used by kubectl so the output is consistent,
// Set environment variables used by kubectl so the output is consistent,
// regardless of where we run.
// regardless of where we run.
os
.
Setenv
(
"HOME"
,
"/home/username"
)
os
.
Setenv
(
"HOME"
,
"/home/username"
)
//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
kubectl
:=
cmd
.
NewKubectlCommand
(
cmdutil
.
NewFactory
(
nil
),
os
.
Stdin
,
ioutil
.
Discard
,
ioutil
.
Discard
)
kubectl
:=
cmd
.
NewKubectlCommand
(
cmdutil
.
NewFactory
(
nil
),
os
.
Stdin
,
ioutil
.
Discard
,
ioutil
.
Discard
)
cobra
.
GenMarkdownTree
(
kubectl
,
docs
Dir
)
cobra
.
GenMarkdownTree
(
kubectl
,
out
Dir
)
}
}
cmd/genman/gen_kubectl_man.go
View file @
55d133ea
...
@@ -21,9 +21,9 @@ import (
...
@@ -21,9 +21,9 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"path/filepath"
"strings"
"strings"
"github.com/GoogleCloudPlatform/kubernetes/cmd/genutils"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
cmdutil
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/cpuguy83/go-md2man/mangen"
"github.com/cpuguy83/go-md2man/mangen"
...
@@ -34,40 +34,28 @@ import (
...
@@ -34,40 +34,28 @@ import (
func
main
()
{
func
main
()
{
// use os.Args instead of "flags" because "flags" will mess up the man pages!
// use os.Args instead of "flags" because "flags" will mess up the man pages!
docsDir
:=
"docs/man/man1/
"
path
:=
"docs/man/man1
"
if
len
(
os
.
Args
)
==
2
{
if
len
(
os
.
Args
)
==
2
{
docsDir
=
os
.
Args
[
1
]
path
=
os
.
Args
[
1
]
}
else
if
len
(
os
.
Args
)
>
2
{
}
else
if
len
(
os
.
Args
)
>
2
{
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s [output directory]
\n
"
,
os
.
Args
[
0
])
fmt
.
Fprintf
(
os
.
Stderr
,
"usage: %s [output directory]
\n
"
,
os
.
Args
[
0
])
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
docsDir
,
err
:=
filepath
.
Abs
(
docsDir
)
outDir
,
err
:=
genutils
.
OutDir
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
err
.
Error
()
)
fmt
.
Fprintf
(
os
.
Stderr
,
"failed to get output directory: %v
\n
"
,
err
)
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
stat
,
err
:=
os
.
Stat
(
docsDir
)
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"output directory %s does not exist
\n
"
,
docsDir
)
os
.
Exit
(
1
)
}
if
!
stat
.
IsDir
()
{
fmt
.
Fprintf
(
os
.
Stderr
,
"output directory %s is not a directory
\n
"
,
docsDir
)
os
.
Exit
(
1
)
}
docsDir
=
docsDir
+
"/"
// Set environment variables used by kubectl so the output is consistent,
// Set environment variables used by kubectl so the output is consistent,
// regardless of where we run.
// regardless of where we run.
os
.
Setenv
(
"HOME"
,
"/home/username"
)
os
.
Setenv
(
"HOME"
,
"/home/username"
)
//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
//TODO os.Stdin should really be something like ioutil.Discard, but a Reader
kubectl
:=
cmd
.
NewKubectlCommand
(
cmdutil
.
NewFactory
(
nil
),
os
.
Stdin
,
ioutil
.
Discard
,
ioutil
.
Discard
)
kubectl
:=
cmd
.
NewKubectlCommand
(
cmdutil
.
NewFactory
(
nil
),
os
.
Stdin
,
ioutil
.
Discard
,
ioutil
.
Discard
)
genMarkdown
(
kubectl
,
""
,
docs
Dir
)
genMarkdown
(
kubectl
,
""
,
out
Dir
)
for
_
,
c
:=
range
kubectl
.
Commands
()
{
for
_
,
c
:=
range
kubectl
.
Commands
()
{
genMarkdown
(
c
,
"kubectl"
,
docs
Dir
)
genMarkdown
(
c
,
"kubectl"
,
out
Dir
)
}
}
}
}
...
...
cmd/genutils/genutils.go
0 → 100644
View file @
55d133ea
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
genutils
import
(
"fmt"
"os"
"path/filepath"
)
func
OutDir
(
path
string
)
(
string
,
error
)
{
outDir
,
err
:=
filepath
.
Abs
(
path
)
if
err
!=
nil
{
return
""
,
err
}
stat
,
err
:=
os
.
Stat
(
outDir
)
if
err
!=
nil
{
return
""
,
err
}
if
!
stat
.
IsDir
()
{
return
""
,
fmt
.
Errorf
(
"output directory %s is not a directory
\n
"
,
outDir
)
}
outDir
=
outDir
+
"/"
return
outDir
,
nil
}
cmd/genutils/genutils_test.go
0 → 100644
View file @
55d133ea
/*
Copyright 2015 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
genutils
import
(
"testing"
)
func
TestValidDir
(
t
*
testing
.
T
)
{
_
,
err
:=
OutDir
(
"./"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
TestInvalidDir
(
t
*
testing
.
T
)
{
_
,
err
:=
OutDir
(
"./nondir"
)
if
err
==
nil
{
t
.
Fatal
(
err
)
}
}
func
TestNotDir
(
t
*
testing
.
T
)
{
_
,
err
:=
OutDir
(
"./genutils_test.go"
)
if
err
==
nil
{
t
.
Fatal
(
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment