Skip to content

Commit 845373d

Browse files
committed
added os.userInfo([options])
1 parent 757e83d commit 845373d

File tree

3 files changed

+230
-42
lines changed

3 files changed

+230
-42
lines changed

generated-docs/Node/OS.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
## Module Node.OS
2+
3+
#### `NetworkInterface`
4+
5+
``` purescript
6+
type NetworkInterface = { address :: String, netmask :: String, family :: String, mac :: String, internal :: Boolean }
7+
```
8+
9+
#### `CPU`
10+
11+
``` purescript
12+
type CPU = { model :: String, speed :: Int, times :: { user :: Milliseconds, nice :: Milliseconds, sys :: Milliseconds, idle :: Milliseconds, irq :: Milliseconds } }
13+
```
14+
15+
#### `OS`
16+
17+
``` purescript
18+
data OS :: Effect
19+
```
20+
21+
#### `loadavg`
22+
23+
``` purescript
24+
loadavg :: forall eff. Eff (os :: OS | eff) { one :: Number, five :: Number, fifteen :: Number }
25+
```
26+
27+
#### `Arch`
28+
29+
``` purescript
30+
data Arch
31+
= X64
32+
| ARM
33+
| IA32
34+
| UnknownArch
35+
```
36+
37+
##### Instances
38+
``` purescript
39+
Eq Arch
40+
Show Arch
41+
```
42+
43+
#### `arch`
44+
45+
``` purescript
46+
arch :: forall eff. Eff (os :: OS | eff) Arch
47+
```
48+
49+
#### `Endianness`
50+
51+
``` purescript
52+
data Endianness
53+
= LittleEndian
54+
| BigEndian
55+
| UnknownEndian
56+
```
57+
58+
##### Instances
59+
``` purescript
60+
Eq Endianness
61+
Show Endianness
62+
```
63+
64+
#### `endianness`
65+
66+
``` purescript
67+
endianness :: forall eff. Eff (os :: OS | eff) Endianness
68+
```
69+
70+
#### `Platform`
71+
72+
``` purescript
73+
data Platform
74+
= Darwin
75+
| FreeBSD
76+
| Linux
77+
| SunOS
78+
| Win32
79+
| UnknownPlatform
80+
```
81+
82+
##### Instances
83+
``` purescript
84+
Eq Platform
85+
Show Platform
86+
```
87+
88+
#### `platform`
89+
90+
``` purescript
91+
platform :: forall eff. Eff (os :: OS | eff) Platform
92+
```
93+
94+
#### `userInfo`
95+
96+
``` purescript
97+
userInfo :: forall eff. { encoding :: String } -> Eff (os :: OS | eff) UserInfo
98+
```
99+
100+
#### `eol`
101+
102+
``` purescript
103+
eol :: Char
104+
```
105+
106+
#### `cpus`
107+
108+
``` purescript
109+
cpus :: forall eff. Eff (os :: OS | eff) (Array CPU)
110+
```
111+
112+
#### `freemem`
113+
114+
``` purescript
115+
freemem :: forall eff. Eff (os :: OS | eff) Number
116+
```
117+
118+
#### `homedir`
119+
120+
``` purescript
121+
homedir :: forall eff. Eff (os :: OS | eff) String
122+
```
123+
124+
#### `hostname`
125+
126+
``` purescript
127+
hostname :: forall eff. Eff (os :: OS | eff) String
128+
```
129+
130+
#### `release`
131+
132+
``` purescript
133+
release :: forall eff. Eff (os :: OS | eff) String
134+
```
135+
136+
#### `tmpdir`
137+
138+
``` purescript
139+
tmpdir :: forall eff. Eff (os :: OS | eff) String
140+
```
141+
142+
#### `totalmem`
143+
144+
``` purescript
145+
totalmem :: forall eff. Eff (os :: OS | eff) Number
146+
```
147+
148+
#### `ostype`
149+
150+
``` purescript
151+
ostype :: forall eff. Eff (os :: OS | eff) String
152+
```
153+
154+
#### `uptime`
155+
156+
``` purescript
157+
uptime :: forall eff. Eff (os :: OS | eff) Seconds
158+
```
159+
160+
#### `networkInterfaces`
161+
162+
``` purescript
163+
networkInterfaces :: forall eff. Eff (os :: OS | eff) (StrMap (Array NetworkInterface))
164+
```
165+
166+

src/Node/OS.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use strict";
2-
3-
// module Node.OS
2+
/* jshint node: true */
43

54
var os = require('os');
65

@@ -19,3 +18,23 @@ exports.tmpdir = os.tmpdir;
1918
exports.totalmem = os.totalmem;
2019
exports.ostype = os.type;
2120
exports.uptime = os.uptime;
21+
exports.userInfoImpl = function (update) {
22+
return function (Nothing) {
23+
return function (Just) {
24+
return function (opts) {
25+
return function () {
26+
var userInfo = os.userInfo(opts);
27+
if (userInfo.shell === null) {
28+
return update(function (x) {
29+
return Just(Nothing);
30+
})(userInfo);
31+
} else {
32+
return update(function (x) {
33+
return Just(Just(x));
34+
})(userInfo);
35+
}
36+
};
37+
};
38+
};
39+
};
40+
};

src/Node/OS.purs

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@ module Node.OS
55
, cpus
66
, Endianness(..), endianness
77
, freemem
8-
, loadavg
98
, homedir
109
, hostname
10+
, loadavg
11+
, networkInterfaces
1112
, Platform(..), platform
1213
, release
1314
, tmpdir
1415
, totalmem
1516
, ostype
1617
, uptime
17-
, networkInterfaces
18+
, userInfo
1819
) where
1920

2021
import Prelude
2122

2223
import Data.Array ((!!))
23-
import Data.Maybe (fromMaybe)
24-
import Data.StrMap (StrMap)
24+
import Data.Maybe (Maybe(..), fromMaybe)
25+
import Data.StrMap (StrMap, update)
2526
import Data.Time.Duration (Milliseconds, Seconds)
2627

2728
import Control.Monad.Eff (Eff, kind Effect)
@@ -41,46 +42,12 @@ type CPU = { model :: String
4142
, idle :: Milliseconds
4243
, irq :: Milliseconds } }
4344

44-
foreign import data OS :: Effect
45-
46-
foreign import eol :: Char
47-
48-
foreign import archImpl :: forall eff. Eff ( os :: OS | eff ) String
49-
50-
foreign import cpus :: forall eff. Eff ( os :: OS | eff ) (Array CPU)
51-
52-
foreign import endiannessImpl :: forall eff. Eff ( os :: OS | eff ) String
53-
54-
foreign import freemem :: forall eff. Eff ( os :: OS | eff ) Number
55-
56-
foreign import homedir :: forall eff. Eff ( os :: OS | eff ) String
57-
58-
foreign import hostname :: forall eff. Eff ( os :: OS | eff ) String
59-
60-
foreign import loadavgImpl :: forall eff. Eff ( os :: OS | eff ) (Array Number)
61-
62-
foreign import platformImpl :: forall eff. Eff ( os :: OS | eff ) String
63-
64-
foreign import release :: forall eff. Eff ( os :: OS | eff ) String
65-
66-
foreign import tmpdir :: forall eff. Eff ( os :: OS | eff ) String
67-
68-
foreign import totalmem :: forall eff. Eff ( os :: OS | eff ) Number
69-
70-
foreign import ostype :: forall eff. Eff ( os :: OS | eff ) String
71-
72-
foreign import uptime :: forall eff. Eff ( os :: OS | eff ) Seconds
73-
74-
foreign import networkInterfaces :: forall eff. Eff ( os :: OS | eff ) (StrMap (Array NetworkInterface))
45+
foreign import data OS :: Effect
7546

7647
loadavg :: forall eff. Eff ( os :: OS | eff ) { one :: Number, five :: Number, fifteen :: Number }
7748
loadavg = pure <<< fromMaybe {one: 0.0, five: 0.0, fifteen: 0.0} <<< extract =<< loadavgImpl
7849
where
79-
extract xs = do
80-
one <- xs !! 0
81-
five <- xs !! 1
82-
fifteen <- xs !! 2
83-
pure {one, five, fifteen}
50+
extract xs = {one: _, five: _, fifteen: _} <$> xs !! 0 <*> xs !! 1 <*> xs !! 2
8451

8552
data Arch = X64 | ARM | IA32 | UnknownArch
8653

@@ -140,3 +107,39 @@ platform = do
140107
"freebsd" -> FreeBSD
141108
"sunos" -> SunOS
142109
_ -> UnknownPlatform
110+
111+
type UserInfo =
112+
{ uid :: Int
113+
, gid :: Int
114+
, username :: String
115+
, homedir :: String
116+
, shell :: Maybe String
117+
}
118+
119+
userInfo :: forall eff. {encoding :: String} -> Eff ( os :: OS | eff ) UserInfo
120+
userInfo = userInfoImpl (flip update "shell") Nothing Just
121+
122+
foreign import eol :: Char
123+
foreign import archImpl :: forall eff. Eff ( os :: OS | eff ) String
124+
foreign import cpus :: forall eff. Eff ( os :: OS | eff ) (Array CPU)
125+
foreign import endiannessImpl :: forall eff. Eff ( os :: OS | eff ) String
126+
foreign import freemem :: forall eff. Eff ( os :: OS | eff ) Number
127+
foreign import homedir :: forall eff. Eff ( os :: OS | eff ) String
128+
foreign import hostname :: forall eff. Eff ( os :: OS | eff ) String
129+
foreign import loadavgImpl :: forall eff. Eff ( os :: OS | eff ) (Array Number)
130+
foreign import platformImpl :: forall eff. Eff ( os :: OS | eff ) String
131+
foreign import release :: forall eff. Eff ( os :: OS | eff ) String
132+
foreign import tmpdir :: forall eff. Eff ( os :: OS | eff ) String
133+
foreign import totalmem :: forall eff. Eff ( os :: OS | eff ) Number
134+
foreign import ostype :: forall eff. Eff ( os :: OS | eff ) String
135+
foreign import uptime :: forall eff. Eff ( os :: OS | eff ) Seconds
136+
foreign import networkInterfaces
137+
:: forall eff
138+
. Eff ( os :: OS | eff ) (StrMap (Array NetworkInterface))
139+
foreign import userInfoImpl
140+
:: forall a eff
141+
. ((a -> Maybe a) -> StrMap a -> StrMap a)
142+
-> Maybe a
143+
-> (a -> Maybe a)
144+
-> {encoding :: String}
145+
-> Eff ( os :: OS | eff ) UserInfo

0 commit comments

Comments
 (0)