Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita4ea942

Browse files
committed
wip
1 parentf85a92b commita4ea942

File tree

5 files changed

+11
-72
lines changed

5 files changed

+11
-72
lines changed

‎cli/configssh.go

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"strings"
1818

1919
"github.com/cli/safeexec"
20+
"github.com/natefinch/atomic"
2021
"github.com/pkg/diff"
2122
"github.com/pkg/diff/write"
2223
"golang.org/x/exp/constraints"
@@ -524,7 +525,7 @@ func (r *RootCmd) configSSH() *serpent.Command {
524525
}
525526

526527
if!bytes.Equal(configRaw,configModified) {
527-
err=writeWithTempFileAndMove(sshConfigFile,bytes.NewReader(configModified))
528+
err=atomic.WriteFile(sshConfigFile,bytes.NewReader(configModified))
528529
iferr!=nil {
529530
returnxerrors.Errorf("write ssh config failed: %w",err)
530531
}
@@ -758,50 +759,6 @@ func sshConfigSplitOnCoderSection(data []byte) (before, section []byte, after []
758759
returndata,nil,nil,nil
759760
}
760761

761-
// writeWithTempFileAndMove writes to a temporary file in the same
762-
// directory as path and renames the temp file to the file provided in
763-
// path. This ensure we avoid trashing the file we are writing due to
764-
// unforeseen circumstance like filesystem full, command killed, etc.
765-
funcwriteWithTempFileAndMove(pathstring,r io.Reader) (errerror) {
766-
dir:=filepath.Dir(path)
767-
name:=filepath.Base(path)
768-
769-
// Ensure that e.g. the ~/.ssh directory exists.
770-
iferr=os.MkdirAll(dir,0o700);err!=nil {
771-
returnxerrors.Errorf("create directory: %w",err)
772-
}
773-
774-
// Create a tempfile in the same directory for ensuring write
775-
// operation does not fail.
776-
f,err:=os.CreateTemp(dir,fmt.Sprintf(".%s.",name))
777-
iferr!=nil {
778-
returnxerrors.Errorf("create temp file failed: %w",err)
779-
}
780-
deferfunc() {
781-
iferr!=nil {
782-
_=os.Remove(f.Name())// Cleanup in case a step failed.
783-
}
784-
}()
785-
786-
_,err=io.Copy(f,r)
787-
iferr!=nil {
788-
_=f.Close()
789-
returnxerrors.Errorf("write temp file failed: %w",err)
790-
}
791-
792-
err=f.Close()
793-
iferr!=nil {
794-
returnxerrors.Errorf("close temp file failed: %w",err)
795-
}
796-
797-
err=os.Rename(f.Name(),path)
798-
iferr!=nil {
799-
returnxerrors.Errorf("rename temp file failed: %w",err)
800-
}
801-
802-
returnnil
803-
}
804-
805762
// sshConfigExecEscape quotes the string if it contains spaces, as per
806763
// `man 5 ssh_config`. However, OpenSSH uses exec in the users shell to
807764
// run the command, and as such the formatting/escape requirements

‎cli/templateedit.go

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cli
33
import (
44
"fmt"
55
"net/http"
6-
"strings"
76
"time"
87

98
"golang.org/x/xerrors"
@@ -17,6 +16,7 @@ import (
1716

1817
func (r*RootCmd)templateEdit()*serpent.Command {
1918
constdeprecatedFlagName="deprecated"
19+
vardaysOfWeekEnum= []string{"monday","tuesday","wednesday","thursday","friday","saturday","sunday","all"}
2020
var (
2121
namestring
2222
displayNamestring
@@ -239,35 +239,14 @@ func (r *RootCmd) templateEdit() *serpent.Command {
239239
Value:serpent.DurationOf(&activityBump),
240240
},
241241
{
242-
Flag:"autostart-requirement-weekdays",
243-
// workspaces created from this template must be restarted on the given weekdays. To unset this value for the template (and disable the autostop requirement for the template), pass 'none'.
242+
Flag:"autostart-requirement-weekdays",
244243
Description:"Edit the template autostart requirement weekdays - workspaces created from this template can only autostart on the given weekdays. To unset this value for the template (and allow autostart on all days), pass 'all'.",
245-
Value:serpent.Validate(serpent.StringArrayOf(&autostartRequirementDaysOfWeek),func(value*serpent.StringArray)error {
246-
v:=value.GetSlice()
247-
iflen(v)==1&&v[0]=="all" {
248-
returnnil
249-
}
250-
_,err:=codersdk.WeekdaysToBitmap(v)
251-
iferr!=nil {
252-
returnxerrors.Errorf("invalid autostart requirement days of week %q: %w",strings.Join(v,","),err)
253-
}
254-
returnnil
255-
}),
244+
Value:serpent.EnumArrayOf(&autostartRequirementDaysOfWeek,append(daysOfWeekEnum,"all")...),
256245
},
257246
{
258247
Flag:"autostop-requirement-weekdays",
259248
Description:"Edit the template autostop requirement weekdays - workspaces created from this template must be restarted on the given weekdays. To unset this value for the template (and disable the autostop requirement for the template), pass 'none'.",
260-
Value:serpent.Validate(serpent.StringArrayOf(&autostopRequirementDaysOfWeek),func(value*serpent.StringArray)error {
261-
v:=value.GetSlice()
262-
iflen(v)==1&&v[0]=="none" {
263-
returnnil
264-
}
265-
_,err:=codersdk.WeekdaysToBitmap(v)
266-
iferr!=nil {
267-
returnxerrors.Errorf("invalid autostop requirement days of week %q: %w",strings.Join(v,","),err)
268-
}
269-
returnnil
270-
}),
249+
Value:serpent.EnumArrayOf(&autostopRequirementDaysOfWeek,append(daysOfWeekEnum,"none")...),
271250
},
272251
{
273252
Flag:"autostop-requirement-weeks",

‎cli/templateversions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ func (r *RootCmd) templateVersionsList() *serpent.Command {
7070
for_,opt:=rangei.Command.Options {
7171
ifopt.Flag=="column" {
7272
ifopt.ValueSource==serpent.ValueSourceDefault {
73-
v,ok:=opt.Value.(*serpent.StringArray)
73+
v,ok:=opt.Value.(*serpent.EnumArray)
7474
ifok {
7575
// Add the extra new default column.
76-
*v=append(*v,"Archived")
76+
_=v.Append("Archived")
7777
}
7878
}
7979
break

‎go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ require (
204204
github.com/gomarkdown/markdownv0.0.0-20231222211730-1d6d20845b47
205205
github.com/google/go-github/v61v61.0.0
206206
github.com/mocktools/go-smtp-mock/v2v2.3.0
207+
github.com/natefinch/atomicv1.0.1
207208
)
208209

209210
require (

‎go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ github.com/muesli/smartcrop v0.3.0 h1:JTlSkmxWg/oQ1TcLDoypuirdE8Y/jzNirQeLkxpA6O
749749
github.com/muesli/smartcropv0.3.0/go.mod h1:i2fCI/UorTfgEpPPLWiFBv4pye+YAG78RwcQLUkocpI=
750750
github.com/muesli/termenvv0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
751751
github.com/muesli/termenvv0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
752+
github.com/natefinch/atomicv1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A=
753+
github.com/natefinch/atomicv1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM=
752754
github.com/niemeyer/prettyv0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
753755
github.com/niklasfasching/go-orgv1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek=
754756
github.com/niklasfasching/go-orgv1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp